Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
31 lines (24 sloc) 1.05 KB
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.mail import send_mail
from django.conf import settings
from contact.forms import forms
def contact(request):
if request.method == 'POST': # If the form has been submitted...
form = ContactForm(request.POST or None) # A form bound to the POST data
if form.is_valid():
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
sender = form.cleaned_data['sender']
cc_myself = form.cleaned_data['cc_myself']
recipients = settings.RECIPIENTS
if cc_myself:
send_mail(subject, message, sender, recipients)
return HttpResponseRedirect('/thankyou/') # Redirect after POST # All validation rules pass
# Process the data in form.cleaned_data
# ...
return HttpResponseRedirect('/thankyou/') # Redirect after POST
form = ContactForm() # An unbound form
return render(request, '/contact/', {'form': form})
Jump to Line
Something went wrong with that request. Please try again.