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.
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.
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.
You should check the code below it:
return render(request, 'polls/detail.html', {
'question': p,
'error_message': "You didn't select a choice.",
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With