2013-10-27 38 views
4

Django的教程部分4具有下面的代碼:哪裏是在Django教程部分定義的變量ERROR_MESSAGE 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> 

我無法找出在ERROR_MESSAGE變量中,如果條件語句定義在哪裏。谷歌搜索,堆棧溢出和django apis似乎沒有給出任何答案。

+0

你能在這裏發表看法碼?它將被視爲一個上下文變量從視圖 – karthikr

+0

視圖代碼可以在這裏找到:https://docs.djangoproject.com/en/1.5/intro/tutorial04 ..mariodev似乎已經回答了它 – exceed

+0

感謝您提出這個問題。 Django教程確實應該在「A quick rundown:」部分中作爲一個重點來解釋這一點。第一次介紹它時不應該被掩蓋。 – Jarad

回答

3

您應該檢查下面的代碼是:

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

啊,謝謝,不知何故,我錯過了,但即時通訊仍然是很新的django – exceed