Advertisement
Guest User

django contact form

a guest
Feb 14th, 2012
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. forms.py
  2.  
  3. from django import forms
  4.  
  5. class ContactForm(forms.Form):
  6.     subject = forms.CharField()
  7.     email = forms.EmailField()
  8.     message = forms.CharField()
  9.  
  10. views.py
  11.  
  12. def contact(request):
  13.     if request.method == 'POST':
  14.         form = ContactForm(request.POST)
  15.         if form.is_valid():
  16.             cd = form.cleaned_data
  17.             send_mail(
  18.                 cd['subject'],
  19.                 cd['message'],
  20.                 cd.get('test@test.megiteam.pl'),
  21.                 ['test@test.megiteam.pl'],
  22.             )
  23.             return HttpResponseRedirect('/contact/thanks/')
  24.     else:
  25.         form = ContactForm()
  26.     csrf_form = {'form': form}
  27.     csrf_form.update(csrf(request))
  28.     return render_to_response('contact_form.html',csrf_form)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement