Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- htmly = render_to_string('newsletter_confirm.html')
- @csrf_exempt
- def subscribe(request):
- template_name = 'subscribe.html'
- try:
- if request.method == 'POST':
- sub = Subscriber(
- email=request.POST['email'], conf_num=random_digits())
- sub.save()
- recent = Blog.objects.all().filter(status="Published").order_by('-created_on')[:3]
- message = Mail(
- from_email=formataddr((str(Header('Pathway To Light', 'utf-8')), settings.FROM_EMAIL)),
- #from_email=settings.FROM_EMAIL,
- to_emails=sub.email,
- subject='Newsletter Confirmation',
- html_content=htmly.format(request.build_absolute_uri('/confirm/'), sub.email, sub.conf_num, {'recent': recent }))
- sg = SendGridAPIClient(settings.SENDGRID_API_KEY)
- response = sg.send(message)
- return render(request, 'pathway/accept.html')
- else:
- form = SubscriberForm()
- return render(request, template_name, {'form': form})
- except IntegrityError:
- return HttpResponse('<script> window.alert("Email already Exists...");window.location.href="/"; </script>')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement