7.3.2 Using TagForm in the Django Shell

To demonstrate the use of TagForm, including the validation and binding data to the form, we can turn to the Django shell (available from your terminal with ./manage shell). In Example 7.4, we invoke the shell, import TagForm, and instantiate the class.

Example 7.4: Python Interpreter Code

>>> from organizer.forms import TagForm >>> tform = TagForm()

As with models, the inheritance of forms.Form affords us all of the behavior Django expects forms to have. Notably, we can see if the form has been given data thanks to the is_bound data attribute, and we can check whether this data has been correctly validated and cleaned thanks to the is_valid() method, shown in Example 7.5 ...

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.