watson.form.decorators

watson.form.decorators.has_csrf(cls)[source]

Adds csrf protection to the form.

Adds a new field named ‘csrf_token’ to the form and overrides the set data method to retrieve the correct token.

If a form is csrf protected then a session object must be passed to the __init__ method so that a token can be created (if not already).

Example:

@has_csrf
class MyForm(Form):
    username = fields.Text(required=True)
    password = fields.Password(required=True)