The base view class from which most custom contact-form views should inherit. If you don’t need any custom functionality, and are content with the default
ContactFormclass, you can also use it as-is (and the provided URLConf, contact_form.urls, does exactly this).
This is a subclass of Django’s
FormView, so refer to the Django documentation for a list of attributes/methods which can be overridden to customize behavior.
One non-standard attribute is defined here:
The list of email addresses to send mail to. If not specified, defaults to the
recipient_listof the form.
Additionally, the following standard (from
FormView) methods and attributes are commonly useful to override (all attributes below can also be passed to
as_view()in the URLconf, permitting customization without the need to write a full custom subclass of
The form class to use. By default, will be
ContactForm. This can also be overridden as a method named
form_class(); this permits, for example, per-request customization (by inspecting attributes of self.request).
str, the template to use when rendering the form. By default, will be contact_form/contact_form.html.
The URL to redirect to after successful form submission. Can be a hard-coded string, the string resulting from calling Django’s
reverse()helper, or the lazy object produced by Django’s
reverse_lazy()helper. Default value is the result of calling
reverse_lazy()with the URL name ‘contact_form_sent’.
Return type: str
Returns additional keyword arguments (as a dictionary) to pass to the form class on initialization.
If you override
get_form_kwargs(), you must ensure that, at the very least, the keyword argument request is still provided, or
ContactForminitialization will raise
TypeError. The easiest approach is to use
super()to call the base implementation in
ContactFormView, and modify the dictionary it returns.
Return type: dict