Django's URL regex engine is failing - regex

Django's URL regex engine is failing and I have no idea why. Even my sanity checks are failing horribly.
Here's my urls.py:
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^a', 'placemyorder.views.home', name='home'),
)
I get this 404 error:
Page not found (404)
Request Method: GET
Request URL: http://[ip address]/a/
Using the URLconf defined in placemyorder.urls, Django tried these URL patterns, in this order:
1. ^a [name='home']
The current URL, , didn't match any of these.
when I visit
http://[ip address]/a
And it's hosted on Django 1.5.2 with Python 2.7.3 on Ubuntu 12.04 behind nginx if that info is relevant.

Here's a clue: The current URL, , didn't match any of these.
It should say: The current URL, http://[ip address]/a, didn't match any of these.
So the dispatcher isn't getting the request url.
Take a look at this solution:
Django + NGINX URL Problem

Related

URLpattern match doesn't work as expected

What I want
I'm running the very first steps of the Django Project tutorial and there's already something i can't get right.
The idea behind include() is to make it easy to plug-and-play URLs. Since polls are in their own URLconf (polls/urls.py), they can be placed under “/polls/”, or under “/fun_polls/”, or under “/content/polls/”, or any other path root, and the app will still work.
I built everything as needed and my 'shelves' server works fine (debug here, running on localhost).
I'm setting the urlpatterns in shelves.urls, the first of which tries to include 'bluebook.urls'.
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('bluebook/', include('bluebook.urls')),
path('admin/', admin.site.urls),
]
When I go to http://127.0.0.1:8000/bluebook/, it works fine and loads the views.index I set up.
What doesn't work
When I go to http://127.0.0.1:8000/thebluebook/, it throws a 404. It goes as far as defining regex match not working :
Using the URLconf defined in shelves.urls, Django tried these URL patterns, in this order:
1. bluebook/
2. admin/
The current path, thebluebook/, didn't match any of these.
It does the same with http://127.0.0.1:8000/the_bluebook/ or http://127.0.0.1:8000/go/bluebook/.
What I tried
I haven't written much code so there's not much to join to this summary. Although the error message only mentions shelves.urls, i checked that bluebook.urls is set to accept any regex after the redirection from shelves.urls :
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
I checked Django Tutorial Part 1 Error: URL does not match URL patterns and tried to change ROOT_URLCONF from 'shelves.urls' to 'urls', but it throws a ERR_CONNECTION_REFUSED instead of a 404, whatever I put after http://127.0.0.1:8000/, basically the site doesn't work anymore.
I checked out Page not found 404 on Django site? but my site's urls.py is in the child folder mysite/, not the parent mysite/.
I also tried
urlpatterns = [
path('bluebook/', 'bluebook.urls'),
path('admin/', admin.site.urls),
]
but it doesn't work either.
Basically, all my setup looks right to me as calling the exact URLpattern works as expected. Only the regex matching doesn't seem to work.
FWIW, I'm using JetBrain's PyCharm to edit the code and setup the venv, without the plugin, but I don't see it influencing the running of Django code.
Python-version : Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Django version : 2.0.7
PyCharm version : 2018.1.4
Chrome version : Version 67.0.3396.99 (Official Build) (64-bit)
You didn't include 'thebluebook' in your urls. you have path('bluebook/', include('bluebook.urls')), and path('', views.index, name='index'),
which means you can do http://127.0.0.1:8000/bluebook/any/thing/here/ but you can not http://127.0.0.1:8000/any/thing/here/bluebook/.

Installed django on hostgator(shared), but it's giving 404 error instead of showing Welcome page

I have installed Django on Hostgator shared plan.
I am able to access to mydomain.ca/admin (actually mydomain.ca/index.fcgi/admin), and able to login as superuser.
However, when I go to mydomain.ca, it displays
Page not found (404)
Request Method: GET
Request URL: http://mydomain.ca/index.fcgi/
Using the URLconf defined in src.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, , didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
If I'm correct, it should show "It worked!" website instead, since I have not added anything to my app yet.
I have followed the tutorial on http://support.hostgator.co.m/articles/django-with-fastcgi
My .htaccess looks exactly same as the one in the tutorial, and my index.fcgi looks like
.#!/home/user/mydjango/bin/python
import os
import sys
sys.path.insert(0, "/home/user/mydjango/source")
os.environ['DJANGO_SETTINGS_MODULE'] = 'src.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
Could anyone assist me to solve this problem?
Thank you!

little trouble while trying to run emencia.django.newsletter

I did exactly (or so I think) as the docs describe to install emencia.django.newsletter (https://github.com/Fantomas42/emencia-django-newsletter). I installed all dependencies and emencia.django.newsletter from github. All installed successfully.
I also added this in my urls.py
urlpatterns += patterns('',
url(r'^newsletters/', include('emencia.django.newsletter.urls')),
)
I synced the database and when I give http://localhost:8000/newsletters/ (even having logged in as admin) I get a 404 error page.
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/newsletters/
[...]
^newsletters/ ^mailing/
^newsletters/ ^tracking/
^newsletters/ ^statistics/
^newsletters/ ^ ^preview/(?P<slug>[-\w]+)/$ [name='newsletter_newsletter_preview']
^newsletters/ ^ ^(?P<slug>[-\w]+)/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$ [name='newsletter_newsletter_contact']
^dowser/
^media/(?P<path>.*)$
Where did I go wrong?
Obviously there is no page at /newsletters/ as you can see in the urls.py.
Try /newsletters/mailing/

Django include url causes rendering error?

I have a working django project. I wrote a small app - pm - and I tried to include its urls.py in the active project:
urlpatterns = patterns('',
# ... some urls here
url(r'^$', views.home, name='vw_home'),
# I added the following line:
(r'^pm/', include('pm.urls')),
Once I access the main web page, I receive the following error:
TemplateSyntaxError at /
Caught error while rendering: syntax error
and the debug shows the problem in the following line:
Home
If I remove the last url pattern (the include()), the page renders without any problem.
How can this be fixed?
EDIT:
Adding the urls.py of the pm app:
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns("pm.views",
url(r'^inbox/$', 'inbox', {'folder': 'inbox'}, name='vw_inbox'),
url(r'^sent/$', 'inbox', {'folder': 'sent'}, name='vw_sent'),
url(r'^message/(?<message_id>\w+)/$', 'read_message', name='vw_read_message'),
url(r'^compose/(?P<profile_id>\w+)/$', 'compose_message', name='vw_compose_message'),
url(r'^reply/(?P<message_id>\w+)/$', 'compose_message', name='vw_reply_message'),
)
url(r'^message/(?<message_id>\w+)/$', 'read_message', name='vw_read_message'),
You missed ?P

admin/appname/modelname urls does not work with mod_wsgi in Django 1.1rc1

I'm using Django 1.1 rc1 and Apache 2.2.8 on Ubuntu with mod_wsgi 1.3.1 + Python 2.5.2.
Everything worked fine with Django's internal testing web server, but after migrating to Apache mod_wsgi, all urls like /admin/appname/modelname/ began not to work. They shows 404 not found errors with the following log:
...
^admin/ ^$
^admin/ ^logout/$
^admin/ ^password_change/$
^admin/ ^password_change/done/$
^admin/ ^jsi18n/$
^admin/ ^r/(?P<content_type_id>\d+)/(?P<object_id>.+)/$
^admin/ ^(?P<app_label>\w+)/$
The current URL, admin/account/userprofile/, didn't match any of these.
Strangely, /admin/appname/ and all other parts including my custom urls just work fine.
Is it a bug of Django or configuration issue? And how to solve it?
I know that 1.1RC1 made some changes to the admin URL resolver to use namespaces: this might be your problem.
see here: http://docs.djangoproject.com/en/dev/releases/1.1-rc-1/
Other than that it looks like the URLs are not correct as the last line of the urls in the debug trace would only match /admin/app/ rather than /admin/app/xxxx. The information here might help.
for some reason this ^admin/ ^r/(?P\d+)/(?P.+)/$ doesn't look right wouldn't that give /admin//xxx/yyy/ ?
Edit: no it gives /admin/r/xxx/yyy/
I can't test this right now as I only have 1.0.2 available on this computer (and no mod_wsgi) - I will test on 1.1 when I get home tonight.
Edit: Looks like this
for model, model_admin in self._registry.iteritems():
urlpatterns += patterns('',
url(r'^%s/%s/' % (model._meta.app_label, model._meta.module_name),
include(model_admin.urls))
)
return urlpatterns
is not working for some reason, as the URLs are not included in the search path in the debug trace. Are the admin.py files correct?