Coverage for pages/views.py: 100.00%

27 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-23 10:02 -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

5 

6from .forms import ContactForm 1a

7 

8 

9class HomePageView(TemplateView): 1a

10 template_name = "pages/home.html" 1a

11 

12 

13class AboutPageView(TemplateView): 1a

14 template_name = "pages/about.html" 1a

15 

16 

17class ProfilePageView(TemplateView): 1a

18 template_name = "pages/profile.html" 1a

19 

20 

21def ContactView(request): 1a

22 if request.method == "GET": 1a

23 form = ContactForm() 1a

24 else: 

25 form = ContactForm(request.POST) 1a

26 if form.is_valid(): 1a

27 subject = form.cleaned_data["subject"] 1a

28 from_email = form.cleaned_data["from_email"] 1a

29 message = form.cleaned_data["message"] 1a

30 try: 1a

31 send_mail(subject, message, from_email, ["admin@example.com"]) 1a

32 except BadHeaderError: 1a

33 return HttpResponse("Invalid header found.") 1a

34 return redirect("success") 1a

35 return render(request, "pages/contact.html", {"form": form}) 1a

36 

37 

38def SuccessView(request): 1a

39 return render(request, "pages/success.html") 1a