Built-in views¶
- class django_contact_form.views.ContactFormView(**kwargs)[source]¶
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,django_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:
- recipient_list¶
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) attributes are commonly useful to override (all attributes below can also be passed toas_view()in the URLconf, permitting customization without the need to write a full custom subclass ofContactFormView). Each of these can be supplied as an attribute, or as a method with the name prefixed withget_(for example, aget_form_class()method instead of aform_classattribute):- form_class¶
The form class to use. By default, will be
ContactForm.
- template_name¶
A
str, the template to use when rendering the form. By default, will bedjango_contact_form/contact_form.html.
- success_url¶
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’sreverse_lazy()helper. Default value is the result of callingreverse_lazy()with the URL name"django_contact_form_sent".
You can also override the following method for full customization of the form instance construction:
- get_form_kwargs() dict[source]¶
Return additional keyword arguments (as a dictionary) to pass to the form class on initialization.
By default, this will return a dictionary containing the current
HttpRequest(as the keyrequest) and, ifrecipient_listwas defined, its value (as the keyrecipient_list).Warning
Request is a required argument
If you override
get_form_kwargs(), you must ensure that, at the very least, the keyword argumentrequestis still provided, orContactForminitialization will raiseTypeError. The easiest approach is to usesuperto call the base implementation inContactFormView, and modify the dictionary it returns.