def contactView(request):
"""
A simple view that shows the Contact form and sends an e-mail to the
administrators when submitted.
"""
submitSuccess = False
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST)
if form.is_valid():
fromEmail = form.cleaned_data['fromEmail']
subject = form.cleaned_data['subject']
message = form.cleaned_data['message']
finalMessage = "From user : " + str(request.user.username) + "\n"
finalMessage += "Return e-mail : " + str(fromEmail) + "\n\n"
finalMessage += ("-" * 30) + "\n\n"
finalMessage += message
# Send the mail
try:
send_mail(subject, finalMessage, fromEmail, settings.EMAIL_CONTACT_LIST)
except BadHeaderError:
return HttpResponse('Invalid e-mail header found.')
submitSuccess = True
context = {
'form' : form,
'submitSuccess' : submitSuccess
}
return render(request, 'contact.html', context)
评论列表
文章目录