How to find form.has_errors OR form.errors and enable the error in the first place

form.has_errors is not documented in the forms api. I did a quick grep of the source code, and I could not find it in either Django 1.3 or my svn checkout of the 1.0.X branch. It seems that it's a mistake in the book you are using.

Checking form.errors in your template is fine.

If you tried to access form.has_errors in the view, you would get an AttributeError. However Django does not complain when try to access an variable that does not exist in the template, so {{ form.has_errors }} fails silently. See the docs on template variables for more info.

To introspect the attributes on the form, use dir on the form object, not the view.

>>> from django.contrib.auth.views import AuthenticationForm
>>> dir(AuthenticationForm)

However I recommend you explore the form api docs instead.

The csrf token is required when you are using Django's cross site request forgery protection.


form.has_errors is just a boolean (True/False). It's a convenience method for testing if a form has errors or not (obviously).

form.errors, on the other hand, is the actual array of errors.

Tags:

Django