Пример #1
0
 def post(self, request):
     form = ContactForm(request.POST)
     if form.is_valid():
         print(form.cleaned_data)
         subject = 'Message from ' + form.cleaned_data.get('name')
         content = "Message from : " + form.cleaned_data.get('name') + \
                   " <" + form.cleaned_data.get('email') + ">\n\n" + \
                   form.cleaned_data.get('message')
         to_address_list = list(
             User.objects.filter(is_superuser=True).values_list('email',
                                                                flat=True))
         send_mail(subject,
                   content,
                   '*****@*****.**',
                   to_address_list,
                   fail_silently=True)
         return render(request,
                       template_name='promotion/index.html',
                       context={"is_success": True})
     else:
         return render(request,
                       template_name='promotion/index.html',
                       context={
                           "is_success": False,
                           'form': form
                       })
Пример #2
0
 def get(self, request):
     template_name = 'promotion/index.html'
     form = ContactForm()
     return render(request, template_name, {'form': form})