View for displaying a form, including rendering of template.
This class inherits from:
This class implements all logic for displaying and processing form submissions, including rendering of templates.
Usage example:
class ContactFormView(FormView):
form_class = ContactForm
template_name = 'contact_form.html'
def form_valid(self, form):
# Do something with the submitted form data
return super(ContactFormView, self).form_valid(form)
def get_success_url(self):
return url_for('contact.form')
An instance of the form class will be available in the template context under the form variable.
Mixin for handling form submissions.
Set this to the form class (WTForms) you want to use.
See also
Handle invalid form submission.
This will render the response with the current form in the context so that the errors can be displayed to the user.
Parameters: | form – Instance of the form class. |
---|---|
Returns: | Response containing the form in the context. |
Handle valid form submission.
This redirects the user to the URL returned by get_success_url(). You want to override this method for processing the submitted form data.
Parameters: | form – Instance of the form. |
---|---|
Returns: | Redirect to URL returned by get_success_url(). |
Return a dict containing the context data.
Returns: | A dict containing the given keyword arguments. |
---|
Return an instance of the form class.
Returns: | Instance form_class. |
---|
Return parameters for creating the form instance.
Returns: | A dict containing the arguments for creating the form instance. |
---|
Return initial form data.
Override this method when the initial form data should be generated dynamically. By default this returns initial.
Returns: | initial. |
---|
Return success URL.
Override this method when the success URL depends on the submitted form data or when it should be generated during an request. By default, this returns success_url.
Returns: | success_url. |
---|
Set this to the initial data for form fields. Example:
initial = {
'title': 'Initial title value',
'body': 'Initial body value.',
}
Set this to the URL the user should be redirected to after a successful form submission.
Mixin for processing form data on GET and POST requests.
Handler for GET requests.
This will call render_to_response with an instance of the form as form in the context data.
Returns: | Output of render_to_response method implementation. |
---|
Handler for POST requests.
On a valid form submission, this will dispatch the request to the form_valid method, else it is dispatched to form_invalid.
Returns: | Output of form_valid or form_invalid. |
---|