2
Loose the myapp bit of the form action.
It should be
<form action="polls/{{poll.id}}/vote" method="post">
This matches the regex in your urls.py file –
url(r'^polls/', include('myapp.urls')),
and then in myapp.urls –
url(r'^(?P<poll_id>\d+)/vote/$', 'vote'),
The include
function means that django is trying to match ^polls/(?P<poll_id>\d+)/vote/$
If you look at the error page your getting you can see the url’s that django’s trying to match against (none of them contain ‘myapp’ it should be polls).
IMPORTANT
When you get further on in the tutorial you’ll see that you shouldn’t be hardcoding urls in your templates (as jpic rightly points out). At this stage you need to swap out the form action for {% url 'polls:vote' poll.id %}
.
6
Don’t hardcode urls
You should not hardcode a URL anywhere – just like for file system paths. You’re not only killing kittens but also making your code less solid !
Reverse urls instaed !
Read about reversing urls for starters, and using named urls for main dish, and about {% url %} templatetag for dessert.
At the time of digestive, you will be a master of Django url system B)
Read the tutorial
In the tutorial you linked, they don’t hardcode urls:
{% url 'polls:vote' poll.id %}
That’s the way to go !!
Make sure you don’t have a hardcoded url anywhere in your templates and your problem will go away.
- [Django]-Is there a better way to check if the values of an AJAX request are valid?
- [Django]-How to get last login ip in django and save to a GenericIPAddressField?
- [Django]-How to customize [Authentication credentials were not provided] error message in Django rest framework
- [Django]-Sync django-piston models when using egg module
- [Django]-What is a distributed messaging system? Specifically what is 'distributed' in it?