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

exc*_*eed 5 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>
Run Code Online (Sandbox Code Playgroud)

我无法找出 if 条件语句中 error_message 变量的定义位置。在 google、stack overflow 和 django apis 上搜索似乎没有给出任何答案。

mar*_*dev 5

你应该检查它下面的代码:

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