First Django app tutorial

38 views
Skip to first unread message

Yufenyuy Veyeh Didier

unread,
May 14, 2018, 7:02:43 AM5/14/18
to Django users
Hi everyone, I'm new to python and Django. I also think I am getting it well. But I have an issue with the first Django app tutorial.
My questions display well redirect to the detail view well and to the vote view well. 
The problem I have is that my question does not display the 'choices' of type radio bellow the question text but displays the vote button of type submit
below is the code for the detail.html template and the image of the view on my browser. 

Can anyone help, please?

<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 />
{% endfor %}
<input type="submit" value="Vote" />
</form>




Daniel Hepper

unread,
May 14, 2018, 7:25:45 AM5/14/18
to django...@googlegroups.com
Your template looks fine, and as the question_text is displayed correctly, it probably safe to assume that your view is correct too.

Two things you can check:
- does this question actually have any related choices? You can check in the admin.
- check your models.py if you actually named the model "Choice". If you named it something else e.g. "Answer", the field on the Question model would be called "answer_set" instead of "choice_set"

Hope that helps,
Daniel

--
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...@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/7f230a60-7c1e-4ae6-8152-9725e9cb01f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cuneyt Mertayak

unread,
May 14, 2018, 1:15:28 PM5/14/18
to Django users
It will be a bit generic help: To understand what's going wrong with your code when you expect other type of behavior you can use debugging tools like: pdb or (if you use an IDE like pycharm) build-in IDE debugger (https://www.jetbrains.com/help/pycharm/debugging-django-templates.html, https://www.jetbrains.com/help/pycharm/debugging-django-templates.html).

I believe you'll get to the root cause of the problem faster with debugger use.
Reply all
Reply to author
Forward
0 new messages