Python 其中是django教程第4部分中定义的变量error_消息
django教程第4部分的代码如下:Python 其中是django教程第4部分中定义的变量error_消息,python,django,scripting,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.ch
{{ 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>
{{poll.question}
{%if error\u message%}{{{error\u message}{%endif%}
{%csrf_令牌%}
{poll.choice_set.all%}
{{choice.choice_text}}
{%endfor%}
我很难找到if条件语句中error_message变量的定义位置。谷歌、stack overflow和django API上的搜索似乎没有给出任何答案。您应该检查下面的代码:
return render(request, 'polls/detail.html', {
'question': p,
'error_message': "You didn't select a choice.",
})
你能在这里发布视图代码吗?可以在这里找到viewview代码中的上下文变量:…mariodev似乎已经回答了itThanks的问题。Django教程真的应该在“快速运行:”部分中包含对此的解释,作为一个要点。当我第一次介绍它的时候,它不应该被掩盖。啊,谢谢,不知何故我错过了,但我对django还是很陌生