django教程第4部分中定义的变量error_message在哪里

时间:2013-10-27 14:57:12

标签: python django scripting

django教程第4部分包含以下代码:

{{ poll.question }}

{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}

<form action="{% url 'polls:vote' poll.id %}" method="post">
{% csrf_token %}
{% for choice in poll.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变量的定义位置。搜索谷歌,堆栈溢出和django apis似乎没有给出任何答案。

1 个答案:

答案 0 :(得分:4)

您应该检查下面的代码:

return render(request, 'polls/detail.html', {
    'question': p,
    'error_message': "You didn't select a choice.",
})