contact form
This commit is contained in:
parent
e9fad9eabf
commit
d5bd8d2da8
13 changed files with 96 additions and 0 deletions
0
app/contact/__init__.py
Normal file
0
app/contact/__init__.py
Normal file
2
app/contact/admin.py
Normal file
2
app/contact/admin.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
from django.contrib import admin
|
||||
|
||||
6
app/contact/apps.py
Normal file
6
app/contact/apps.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ContactConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'app.contact'
|
||||
7
app/contact/forms.py
Normal file
7
app/contact/forms.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
from django import forms
|
||||
from django.conf import settings
|
||||
|
||||
class ContactForm(forms.Form):
|
||||
email = forms.EmailField(label='EMail', required=False)
|
||||
message = forms.CharField(label='Message', required=True)
|
||||
|
||||
0
app/contact/migrations/__init__.py
Normal file
0
app/contact/migrations/__init__.py
Normal file
2
app/contact/models.py
Normal file
2
app/contact/models.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
from django.db import models
|
||||
|
||||
3
app/contact/tests.py
Normal file
3
app/contact/tests.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
20
app/contact/views.py
Normal file
20
app/contact/views.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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)
|
||||
else:
|
||||
context['form'] = form
|
||||
return render(request, 'contact.html', context)
|
||||
Loading…
Add table
Add a link
Reference in a new issue