Coverage for pages/views.py: 100.00%
25 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-04 19:48 -0700
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-04 19:48 -0700
1from django.core.mail import BadHeaderError, send_mail 1a
2from django.http import HttpResponse 1a
3from django.shortcuts import redirect, render 1a
4from django.views.generic import TemplateView 1a
6from .forms import ContactForm 1a
9class HomePageView(TemplateView): 1a
10 template_name = "pages/home.html" 1a
13class AboutPageView(TemplateView): 1a
14 template_name = "pages/about.html" 1a
17def ContactView(request): 1a
18 if request.method == "GET": 1a
19 form = ContactForm() 1a
20 else:
21 form = ContactForm(request.POST) 1a
22 if form.is_valid(): 1a
23 subject = form.cleaned_data["subject"] 1a
24 from_email = form.cleaned_data["from_email"] 1a
25 message = form.cleaned_data["message"] 1a
26 try: 1a
27 send_mail(subject, message, from_email, ["admin@example.com"]) 1a
28 except BadHeaderError: 1a
29 return HttpResponse("Invalid header found.") 1a
30 return redirect("success") 1a
31 return render(request, "pages/contact.html", {"form": form}) 1a
34def SuccessView(request): 1a
35 return render(request, "pages/success.html") 1a