【发布时间】:2016-04-25 11:43:29
【问题描述】:
人!我正在做 Django 教程。
https://docs.djangoproject.com/en/1.9/intro/tutorial04/#write-a-simple-form
我被困在这里。这是detail.html模板代码:
<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>
我不明白这些事情:
- {% if error_message %}
- {{ forloop.counter }}
- 在 question.choice_set.all 值为choice_set.all。它来自哪里?
本教程的单独步骤看起来很清晰,但随后出现了一些代码的和平和我正在做的事情的清晰性消失了。
提前致谢。
【问题讨论】:
标签: django-templates