Yesterday I was working on my first app using this tutorial. It\'s a Poll and Choice app. The first page displays the question and when you click on the question it\'s suppose t
The answer is to add namespaces to your root URLconf. In the mysite/urls.py file (the project’s urls.py, not the application’s), go ahead and change it to include namespacing:
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls', namespace="polls")),
url(r'^admin/', include(admin.site.urls)),
)
Furthermore, in part 3 of the tutorial Namespacing URL names the use of app_name is mentioned as the accepted way for adding the polls namespace. You can add the line for this in your polls/urls.py as follows:
app_name = 'polls'
urlpatterns = [
...
]
The problem is in the tutorial. While adding the namespace( in your case 'myapp') to your URLconf, the tutorial uses the following code of line:
app_name = 'myapp'
The Django framework for some reason treats it as a unicode string. Instead please enclose the name of your app in double quotes instead of single quotes. For example,
app_name = "myapp"
This will most certainly solve your problem. I had the same problem and doing so solved it.
You need to add the following line to the top of the detail.html:
{% load url from future %}
(Notice you've already used this line in the index.html in order to use the polls namespace)
Inside myapp/urls.py add the following module-level attribute:
app_name = "polls"
This will set the "application namespace name" for that application. When you use names like "polls:submit" in a reverse, Django will look in two places: application namespaces (set like above), and instance namespaces (set using the namespace= parameter in the "url" function). The latter is important if you have multiple instances of an app for your project, but generally it's the former you want.
I had this very issue, and setting namespace= into the url() function seemed wrong somehow.
See this entry of the tutorial: https://docs.djangoproject.com/en/1.9/intro/tutorial03/#namespacing-url-names
Update: this information is correct for Django 1.9. Prior to 1.9, adding a namespace= attribute to the include is, indeed, the proper way.
Restart the web server. Just that.
Replacing the line:
{% url 'polls:vote' poll.id %}
with:
{% url 'vote' poll.id %}
worked out for me...