from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
def contact_form(request, form_class=ContactForm,
+ success_url=, fail_silently=False):
Render a contact form, validate its input and send an email
The URL to redirect to after a successful submission. If not
- supplied, this will be the URL ``/contact/sent/``.
+ supplied, this will default to the URL pointed to by the named
+ URL pattern ``contact_form_sent``.
The template to use for rendering the contact form. If not
+ # We set up success_url here, rather than as the default value for
+ # the argument. Trying to do it as the argument's default would
+ # mean evaluating the call to reverse() at the time this module is
+ # first imported, which introduces a circular dependency: to
+ # perform the reverse lookup we need access to contact_form/urls.py,
+ # but contact_form/urls.py in turn imports from this module.
+ if success_url is None:
+ success_url = reverse('contact_form_sent')
if request.method == 'POST':
form = form_class(data=request.POST, files=request.FILES, request=request)