Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the variable error_message defined in django tutorial part 4

The django tutorial part 4 has the following code:

{{ 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>

I'm having trouble finding out where the error_message variable in the if conditional statement is defined. Searches on google, stack overflow and the django apis doesnt seem to give any answer on this.

like image 276
exceed Avatar asked Oct 27 '13 14:10

exceed


People also ask

How do I link pages in Django?

Just use the same label {% url 'index' %} . You may use each name in urls.py to link to the url. Show activity on this post. Create a new URL in the same format and give that name instead of index.

What is _( in Django?

In Django _() is an alias to ugettext(). This is covered in the django docs. I'm aware that _() is used, by convention, as an alias to ugettext() in Python code, but not in templates. And since we all don't put something like from django.


1 Answers

You should check the code below it:

return render(request, 'polls/detail.html', {
    'question': p,
    'error_message': "You didn't select a choice.",
})
like image 146
mariodev Avatar answered Sep 22 '22 21:09

mariodev