added contact form

This commit is contained in:
DerTyp187
2021-11-25 10:57:40 +01:00
parent 7503846d4c
commit f2c9d3216b
16 changed files with 177 additions and 1 deletions

30
TealCode/contact/views.py Normal file
View File

@@ -0,0 +1,30 @@
from django.shortcuts import redirect, render
from .forms import EntryForm
def index(req):
if req.method == "POST":
form = EntryForm(req.POST)
if form.is_valid:
entry = form.save()
entry.ip = ip=get_ip(req)
entry.save()
form = False
else:
form = EntryForm()
context = {
'current': 'contact',
'form': form,
}
return render(req, "contact/index.html", context)
def get_ip(req):
ip = req.META.get('HTTP_X_REAL_IP')
if ip is None:
return "x.x.x.x"
else:
# We got the client's IP address
return ip