我在Django tutorial (part 4)上,嘗試創建一個允許用戶選擇投票答案的表單。這些問題正確加載,但是當我點擊「投票」(即選擇選項,並提交形式)以下錯誤不斷顯示:表單提交在Django中保持失敗教程
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">
行,但我不知道如何解決它。
Right on ...與網址匹配的模式錯誤。 –
是啊...這一直髮生:) –