diff options
Diffstat (limited to 'contact/views.py')
-rw-r--r-- | contact/views.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/contact/views.py b/contact/views.py new file mode 100644 index 0000000..e3a6511 --- /dev/null +++ b/contact/views.py | |||
@@ -0,0 +1,26 @@ | |||
1 | from django.shortcuts import render, redirect | ||
2 | from django.core.mail import send_mail | ||
3 | |||
4 | from contact.forms import ContactForm | ||
5 | |||
6 | |||
7 | def contact_form(request): | ||
8 | return render(request, 'contact/form.html', { | ||
9 | 'form': ContactForm(), | ||
10 | }) | ||
11 | |||
12 | |||
13 | def contact_processor(request): | ||
14 | if request.method != "POST": | ||
15 | return redirect("contact:form") | ||
16 | |||
17 | form = ContactForm(request.POST) | ||
18 | if not form.is_valid(): | ||
19 | return redirect("contact:form") | ||
20 | |||
21 | send_mail(form.cleaned_data['subject'], form.cleaned_data['message'], | ||
22 | form.cleaned_data['sender'], ['codemash@example.com']) | ||
23 | |||
24 | return render(request, 'contact/thanks.html', { | ||
25 | 'form': form, | ||
26 | }) | ||