def contact(request):
form = ContactForm()
if request.POST:
form = ContactForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
send_mail(
cd['subject'],
cd['message'],
cd.get('email', 'noreply@example.com'),
['my@mail.ru'],
)
return HttpResponseRedirect('/')
else:
form = ContactForm()
return render_to_response('contact.html', {'form': form}, context_instance=RequestContext(request))
ZGVmIGNvbnRhY3QocmVxdWVzdCk6CiAgICBmb3JtID0gQ29udGFjdEZvcm0oKQogICAgaWYgcmVxdWVzdC5QT1NUOgogICAgICAgIGZvcm0gPSBDb250YWN0Rm9ybShyZXF1ZXN0LlBPU1QpCiAgICAgICAgaWYgZm9ybS5pc192YWxpZCgpOgogICAgICAgICAgICBjZCA9IGZvcm0uY2xlYW5lZF9kYXRhCiAgICAgICAgICAgIHNlbmRfbWFpbCgKICAgICAgICAgICAgICAgIGNkWydzdWJqZWN0J10sCiAgICAgICAgICAgICAgICBjZFsnbWVzc2FnZSddLAogICAgICAgICAgICAgICAgY2QuZ2V0KCdlbWFpbCcsICdub3JlcGx5QGV4YW1wbGUuY29tJyksCiAgICAgICAgICAgICAgICBbJ215QG1haWwucnUnXSwKICAgICAgICAgICAgKQogICAgICAgICAgICByZXR1cm4gSHR0cFJlc3BvbnNlUmVkaXJlY3QoJy8nKQogICAgZWxzZToKICAgICAgICBmb3JtID0gQ29udGFjdEZvcm0oKQogICAgcmV0dXJuIHJlbmRlcl90b19yZXNwb25zZSgnY29udGFjdC5odG1sJywgeydmb3JtJzogZm9ybX0sIGNvbnRleHRfaW5zdGFuY2U9UmVxdWVzdENvbnRleHQocmVxdWVzdCkp