O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required