Created
May 15, 2012 06:03
-
-
Save dingzhihu/2699479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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