Tuesday, April 4, 2017

Follow the django tutorial but failure

Hi,
I'm try to follow the Django tutorial and modify something but failure.
When I execute the web page is error and the Django server console said " Method not allowed (Post): /polls/3/results/"
But I'm type address : http://127.0.0.1:8000/polls/3/results/ is fine, thanks

In "First app, Part 4",
I created Index List view and the Detail & Results , DetailView

In "detail.html" I try to modify below coding

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Detail</title>
</head>
<body>
<h1>{{ question.question_text }}</h1>
{% if error_message %}<p><strong>{{error_message}}</strong></p>{% endif %}

<form action="{% url 'polls:results' 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_text }}</label><br />
{% endfor %}
<input type="submit" value="Vote" />

</form>
</body>
</html>

In the "url.py"
from django.conf.urls import url

from . import views

app_name = 'polls'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
# url(r'^$', views.index, name='index'),
# url(r'^(?P<question_id>[0-9]+)/$', views.detail, name='detail'),
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
url(r'^(?P<pk>[0-9]+)/results/$', views.ResultsView.as_view(), name='results'),
# url(r'^(?P<question_id>[0-9]+)/results/$', views.results, name='results'),
url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/91e4a365-33af-437c-a76b-7f8b88c143cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment