This module contains the built-in forms as well as the form base class.
Represents the logic for an HTML form.
Parameters: |
|
---|
The private reCAPTCHA api key.
New in version 0.2.
The public reCAPTCHA api key.
New in version 0.2.
Validates the given form_data.
Parameter: | without_csrf_protection – Pass True if you want to turn of the csrf protection for a validation e.g. if you want to validate form data you got via an JSON/XML API of your application. |
---|
Changed in version 0.2: form_data values are now converted to unicode if necessary.
The base class for forms. Fields can be assigned declarativly, on a created class or on an instance:
class LoginForm(Form):
username = TextField(label=u"Username", required=True)
password = PasswordField(label=u"Password", required=True)
repeat_password = password.copy(label=u"Repeat password",
equals="password")
permanent = BooleanField(label=u"Keep me logged in")
Fields can be accessed as an attribute or dict-like using LoginForm()["username"].
Sometimes you may want to validate a field in a way which only makes sense in the context of the form type you are defining. In order to do that you define a method with the name validate_FIELD_NAME. Such a method gets the value of the field FIELD_NAME as an argument.
If you want to validate the form itself you can define a validate_context method which get’s called upon validation.
Parameters: |
|
---|
New in version 0.2: validate_* methods.
The fields of this form.
Note
Adding fields directly to this dictionary won’t bind them. Use Form().new_field = Field() instead.