def pages(cls, request, slug): if slug == 'contact': if request.method == 'GET': form = forms.ContactForm() elif request.method == 'POST': form = forms.ContactForm(request.POST) if form.is_valid(): try: send_mail( request.POST['subject'], request.POST['message'], request.POST['email'], [settings.EMAIL_TARGET], fail_silently=False, ) messages.success( request, 'Thank you for contacting us. Your query has been forwarded to the relevent department!') return redirect(reverse('web:page', args=('contact',))) except BadHeaderError as error: messages.error(request, str(error)) return render(request, 'pages/' + slug + '.html', { 'form': form, }) else: return render(request, 'pages/' + slug + '.html')
def form(self): return forms.ContactForm(self)
def form(self): return forms.ContactForm(self.request.POST)