Tutorial_4 Forms and generic views 发表于 2017-04-23 | 分类于 Python | | 12345678910<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循环了多少次。 坚持原创技术分享,您的支持将鼓励我继续创作! 赏 微信打赏 支付宝打赏