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
I think you missed the namespace:
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls', namespace="polls")),
)
Django 2.0
in yourapp/urls.py
from django.urls import path
from . import views
app_name = 'yourapp'
urlpatterns = [
path('homepage/', views.HomepageView.as_view(), name='homepage'),
]
in urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('yourapp/', include('yourapp.urls')),
]
namespace should be added polls/urls.py file.
url(r'^myapp/$', include('myapp.urls', namespace ='myapp')),
from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf import settings
urlpatterns = patterns('myapp.views',
url(r'^$', 'index', name="index"),
url(r'^(?P<poll_id>\d+)/$', 'detail', name="detail"),
url(r'^(?P<poll_id>\d+)/results/$', 'results', name="results"),
url(r'^(?P<poll_id>\d+)/vote/$', 'vote', name="vote"),
)
----------------------------------
<h1>{{ poll.question }}</h1>
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
<form method="post" action="{% url myapp:vote poll.id %}">
{% csrf_token %}
{% for choice in poll.choice_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />
<label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br />
{% endfor %}
<input type="submit" value="Vote" />
</form>
I also faced the same issue.
it is fixed now by adding
app_name = "<name of your app>" in app/urls.py
For anyone using "django-hosts":
I had the same error and for me adding this to my template solved it (without any us of namespace etc.):
{% load hosts %}
<a href="{% host_url 'YOUR_URL' host 'YOUR_HOST' %}">Admin dashboard</a>
Additionaly I added PARENT_HOST = 'YOUR_PARENT_HOST' to my settings.py
Reference