コード例 #1
0
ファイル: views.py プロジェクト: schajee/ekan
    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')
コード例 #2
0
 def form(self):
     return forms.ContactForm(self)
コード例 #3
0
 def form(self):
     return forms.ContactForm(self.request.POST)