【发布时间】:2012-11-01 17:00:15
【问题描述】:
我在Django tutorial (part 4) 上并尝试创建一个允许用户选择投票答案的表单。问题加载正常,但是当我点击“投票”(即选择选项并提交表单)时,会一直显示以下错误:
Page not found (404)
Request Method: POST
Request URL: http://localhost:8000/polls/vote/6
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/ ^$ [name='index']
^polls/ ^(?P<poll_id>\d+)/$ [name='detail']
^polls/ ^(?P<poll_id>\d+)/results/$ [name='results']
^polls/ ^(?P<poll_id>\d+)/vote/$ [name='vote']
^admin/
The current URL, polls/vote/6, didn't match any of these.
这是来自 detail.html 的代码,格式如下:
{{ poll.question }}
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
<form action="/polls/vote/{{ poll.id }} " method="post">
{% 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>
我怀疑问题出在<form action="/polls/vote/{{ poll.id }} " method="post"> 行,但我不确定如何解决。
【问题讨论】: