tmonteit
asked on
Django url problem
Hello,
I am working through the django tutorial (Poll/Choice) part 3. What is happening is that django is not recognizing any of my urls based on my urls.py. How do I debug this since I think I'm passing it correct values? Am I building my url regex's correctly?
----------
Page not found (404)
Request Method: GET
Request URL: http://192.168.1.6:8080/polls/34/
Using the URLconf defined in myseite.urls, Django tried these URL patterns, in this order:
1. ^polls/ ^polls/
2. ^polls/ ^polls/(?P<poll_id>\d+)/$
3. ^polls/ ^polls/(?P<poll_id>\d+)/re sults/$
4. ^polls/ ^polls/(?P<poll_id>\d+)/vo te/$
5. ^polls/ ^admin/doc/
6. ^polls/ ^admin/
7. ^admin/doc/
8. ^admin/
The current URL, polls/34/, 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.
I am working through the django tutorial (Poll/Choice) part 3. What is happening is that django is not recognizing any of my urls based on my urls.py. How do I debug this since I think I'm passing it correct values? Am I building my url regex's correctly?
----------
Page not found (404)
Request Method: GET
Request URL: http://192.168.1.6:8080/polls/34/
Using the URLconf defined in myseite.urls, Django tried these URL patterns, in this order:
1. ^polls/ ^polls/
2. ^polls/ ^polls/(?P<poll_id>\d+)/$
3. ^polls/ ^polls/(?P<poll_id>\d+)/re
4. ^polls/ ^polls/(?P<poll_id>\d+)/vo
5. ^polls/ ^admin/doc/
6. ^polls/ ^admin/
7. ^admin/doc/
8. ^admin/
The current URL, polls/34/, 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.
1 urls.py
4 admin.autodiscover()
5
6 urlpatterns = patterns('',
7 (r'^polls/$', 'index'),
8 (r'^polls/(?P<poll_id>\d+)/$', 'detail'),
9 (r'^polls/(?P<poll_id>\d+)/results/$', 'results'),
10 (r'^polls/(?P<poll_id>\d+)/vote/$', 'vote'),
11 (r'^admin/doc/', include('django.contrib.admindocs.urls')),
12 (r'^admin/', include(admin.site.urls)),
13 )
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am sending the following url to the server: http://192.168.1.6:8080/polls/
I am also experimenting with the urls.py. Some strange results
correctly displays the index page:
7 (r'^.*', 'polls.views.index'),
Complains with 404 error:
7 (r'^p.*', 'polls.views.index'),
I'm not a regex expert but I never expected that type of error from the django tutorial.
I am also experimenting with the urls.py. Some strange results
correctly displays the index page:
7 (r'^.*', 'polls.views.index'),
Complains with 404 error:
7 (r'^p.*', 'polls.views.index'),
I'm not a regex expert but I never expected that type of error from the django tutorial.
ASKER
Ok... I figured this out. Turns out that this was getting to my urls.py through a redirection. If you redirect the url, the 'polls' is stripped. if I remove 'polls' from each of the lines it magically works. Go figure.
Thanks for the feedback.
From the initial error message Request URL was the error not obvious.
From the initial error message Request URL was the error not obvious.
ASKER
The error message seems to indicate that the regex isn't matching what is in the url. Do you see anything wrong with the regex? Or is there something else that could be causing this?
Thanks!
T