Skip to content

Instantly share code, notes, and snippets.

@dingzhihu
Created May 15, 2012 06:03
Show Gist options
  • Save dingzhihu/2699479 to your computer and use it in GitHub Desktop.
Save dingzhihu/2699479 to your computer and use it in GitHub Desktop.
from django.shortcuts import render_to_response
from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from django.template import RequestContext
def contact(req):
errors = []
if req.method == 'POST':
if not req.POST.get('subject'):
errors.append('Enter a subject')
if not req.POST.get('message'):
errors.append('Enter a message')
if req.POST.get('email') and '@' not in req.POST['email']:
errors.append('Enter a valid e-mail address.')
if not errors:
send_mail(
req.POST['subject'],
req.POST['message'],
req.POST.get('email','noreply@example.com'),
['601859657@qq.com'],
)
assert False
return HttpResponseRedirect('/contact/thanks/')
return render_to_response('contact_form.html',{'errors':errors},context_instance=RequestContext(req))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment