Django url problem

tmonteit
tmonteit used Ask the Experts™
on
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+)/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.



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     )

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Systems architect
Top Expert 2006
Commented:
From this link:
http://docs.djangoproject.com/en/1.2/intro/tutorial03/

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'),



Author

Commented:
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?
Thanks!
T

Author

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

 

Author

Commented:
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.
ZvonkoSystems architect
Top Expert 2006

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