我正在关注Django教程。在建立投票表格的那一刻,我已经达到了第4部分。遗憾的是,我找不到导致以下错误的问题:
NoReverseMatch at / polls / 1 / vote /
反向投票'有参数'('',)'和关键字参数' {}'未找到。尝试了1种模式:[u'民意调查/(?P [0-9] +)/投票/ $']
/polls/1/vote
和/polls/1/
都会引发上述错误。
我的polls/urls.py
from django.conf.urls import url
from . import views
app_name = 'polls'
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^(?P<question_id>[0-9]+)/$', views.details, name='details'),
url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'),
url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
]
这里是details.html
,显示第11行的错误,form
开头标记:
<h1>{{ question.question }}</h1>
{% if error %}
<p>
<strong>
{{ error }}
</strong>
</p>
{% endif %}
<form action="{% url 'polls:vote' question_id %}" method="POST">
{% csrf_token %}
{% for choice in question.choice_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}"/>
<label for="choice{{ forloop.counter }}">{{ choice.choice }}</label>
<br/>
{% endfor %}
<input type="submit" value="Vote">
</form>