Reputation: 33
I have just started teaching myself python/django and have been following the django tutorials. I have got stuck at the decoupling of URLConfs. I have copied the code to respective files from the tutorial but I am getting this error:
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/ ^/$
^polls/ ^/(?P<poll_id>\d+)/$
^polls/ ^/(?P<poll_id>\d+)/results/$
^polls/ ^/(?P<poll_id>\d+)/vote/$
^admin/
The current URL, polls/, didn't match any of these.
I have got urls.py in both mysite and polls folder as asked by the tutorial (https://docs.djangoproject.com/en/dev/intro/tutorial03/)
Upvotes: 2
Views: 1222
Reputation: 2173
Short answer: remove the first /
in the URL configs on polls.urls
.
Long explanation: The problem here, as Julian mentioned in the comments is that you have an extra slash in the URL configs.
When you have the following in your root URL config:
url(r'^polls/', include('polls.urls')),
This essentially 'chops off' the polls/
part of the URL string and passes the rest on to polls.urls
. So if you try and get the URL polls/13/results
, the polls/
will be handled by my site.urls
and the rest will be given to polls.urls
.
Your polls.urls
file seems to be requiring a preceding /
on the string however, and because this has been removed already it doesn't exist. The caret ^
character means the beginning of the string so all of your configs at the moment require that they start with a /
at the point that polls.urls
receives them, they shouldn't do this otherwise you are expecting the following:
/polls//13/results
instead of:
/polls/13/results
I hope this answers everything!
Upvotes: 2