美文网首页
Tutorial_4:Forms and generic vie

Tutorial_4:Forms and generic vie

作者: longgb246 | 来源:发表于2017-04-23 16:47 被阅读0次

一、表单

<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>

其中forloop.counter是指for循环了多少次。

相关文章