Hi everyone. I am trying to walk through the polls tutorial. I am
stuck at the part 4 after the change of the views from function
based to class based. A search in Google brought plenty results but
none of them seems to be related exactly to this situation or maybe
it is over my head to understand what is going on.
When I visit
http://127.0.0.1:8000/polls/
i get
NoReverseMatch
at /polls/
Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}' not found.
| Request Method: |
GET |
| Request URL: |
http://127.0.0.1:8000/polls/ |
| Django Version: |
1.5.2 |
| Exception Type: |
NoReverseMatch |
| Exception Value: |
Reverse for 'detail' with arguments '(1,)' and keyword arguments '{}' not found.
|
...
In
templateοΏ½/home/voger/PycharmProjects/mysite/polls/templates/polls/index.html,
error at lineοΏ½4
Reverse for 'detail' with
arguments '(1,)' and keyword arguments '{}' not found.
| 1 |
{% if
latest_poll_list %}
|
| 2 |
<ul>
|
| 3 |
{% for poll in
latest_poll_list %}
|
| 4 |
<li><a
href="{% url
'detail' poll.id %}">{{ poll.question
}}</a></li>
|
| 5 |
{% endfor %}
|
| 6 |
</ul>
|
| 7 |
{% else %}
|
| 8 |
<p>No polls
are available.</p>
|
| 9 |
{% endif %} |
The offending line is line number 4. The classes used are
class IndexView(generic.ListView):
οΏ½οΏ½οΏ½ template_name = 'polls/index.html'
οΏ½οΏ½οΏ½ context_object_name = 'latest_poll_list'
οΏ½οΏ½οΏ½ def get_queryset(self):
οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ """Return the last five published polls."""
οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½οΏ½ return Poll.objects.order_by('-pub_date')[:5]
class DetailView(generic.DetailView):
οΏ½οΏ½οΏ½ model = Poll
οΏ½οΏ½οΏ½ template_name = 'polls/detail.html'
and in /polls/urls.py the urls are
urlpatterns = patterns('',
οΏ½οΏ½οΏ½ url(r'^$', views.IndexView.as_view(), name='index'),
οΏ½οΏ½οΏ½ url(r'^(?P<pk>\d+)/$', views.DetailView.as_view(),
name='detail'),
οΏ½οΏ½οΏ½ url(r'^(?P<pk>\d+)/results/$',
views.ResultsView.as_view(), name='results'),
οΏ½οΏ½οΏ½ url(r'^(?P<poll_id>\d+)/vote/$',
views.vote, name='vote'),
)
Can someone please explain what is wrong?