Django url problem

tmonteit used Ask the Experts™

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  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:

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+)/results/$
   4. ^polls/ ^polls/(?P<poll_id>\d+)/vote/$
   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.

    4 admin.autodiscover()
    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(,
   13     )

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Systems architect
Top Expert 2006
From this link:

I read that you are missing in line 8 the prefix: polls.views.

You write this:
(r'^polls/(?P<poll_id>\d+)/$', 'detail'),

It should be this:
(r'^polls/(?P<poll_id>\d+)/$', 'polls.views.detail'),


Thanks for the suggestion.  I replaced all the url targets with 'polls.views.method' and it didn't fix the problem.  
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?


I am sending the following url to the server:
I am also experimenting with the  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.



Ok... I figured this out.  Turns out that this was getting to my 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.
ZvonkoSystems architect
Top Expert 2006

Thanks for the feedback.
From the initial error message Request URL was the error not obvious.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial