phantasma/app/contact/views.py

23 lines
791 B
Python
Raw Normal View History

2021-10-26 16:02:11 +00:00
from django.conf import settings
2021-10-26 15:47:06 +00:00
from django.shortcuts import render
from . import forms
from . import models
def index(request):
context = {
}
if request.method == 'POST':
form = forms.ContactForm(request.POST)
if form.is_valid():
message = 'From: %s\n\n%s' % (form.cleaned_data['email'], form.cleaned_data['message'])
subject = 'Phantas.ma/polis contact message'
from_ = settings.CONTACT_FROM_EMAIL
to = settings.CONTACT_TO_EMAIL
msg = EmailMessage(subject, message, from_, to, reply_to=[form.cleaned_data['email']])
msg.send(fail_silently=True)
2021-10-26 15:51:56 +00:00
context['submitted'] = True
2021-10-26 15:47:06 +00:00
else:
context['form'] = form
return render(request, 'contact.html', context)