Writing your first Django app, part 4

43 views
Skip to first unread message

friscos...@gmail.com

unread,
Mar 5, 2017, 2:13:14 PM3/5/17
to Django users
I'm in the process of learning Django and working throught the tutorial, Writing your first Django app. I'm getting stuck on part 4.  The form n detail.html doesn't display radio buttons.  Thus there is nothing to select and when I submit the form, I get the message, "You didn't select a choice."

Thoughts?

Thanks,
Phil

ludovic coues

unread,
Mar 5, 2017, 3:02:44 PM3/5/17
to django...@googlegroups.com
You didn't share your code, so all we can do is guess.
My guess is that your poll don't have any answer so there is nothing to render.

Try using this form:

<h1>{{ question.question_text }}</h1>

{% if error_message %}<p><strong>{{ error_message }}</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_text
}}</label><br />
{% else %}
<p>There is no choice for this question! Add one in the admin.</p>
{% endfor %}
<input type="submit" value="Vote" />
</form>
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@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/1ccefa6a-4a5a-46bd-8b21-139349da8782%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

friscos...@gmail.com

unread,
Mar 6, 2017, 1:25:02 PM3/6/17
to Django users
Duh,  thanks, I must have missed that step in the tutorial.  Works great now.
Reply all
Reply to author
Forward
0 new messages