8.2.2 Displaying Form Errors in tag_form.html

Recall that our template RequestContext is passed the unbound or bound form variable. In the case of a bound form, we have access to a dictionary named errors, which allows us to print an error by using the name of the field as attribute. For example, should our name field have an error, we can print the error text with {{ form.errors.name }}. Further recall that a template will not error in the event we call a template variable that does not exist. Consequently, we can call or reference values of form without checking for their existence.

Consider that we can check all of these values in the interpreter, accessed in the command line by ./manage.py shell, as shown in Example 8.2.

Example 8.2: Python ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.