Я хочу отправить html-письмо на какой-то адрес.
Это часть моего кода:
views.py
def addNewEvent(request):
try:
eventStatus = EventStatus.objects.filter(event=request.GET["id"])[0]
#try to send the mail
html = get_template('mail.html')
d = Context({ 'username': usuario.name,'title':'Testing mail!!','eventStatusId': str(eventStatus.id)})
html_content = html.render(d)
msg = EmailMultiAlternatives('Testing yo','Skyforger!', '[email protected]', [[email protected]])
msg.attach_alternative(html_content, "text/html")
msg.send()
print('EventStatus id '+str(eventStatus.id))
except Exception, e:
print ('the error %s',(str(e)))
response = getBaseJSON()
response["event_id"]= eventStatus.id
return HttpResponse(json.dumps(response), content_type="application/json")
mail.html
<html>
<body>
<h1>{{title}}</h1>
<h2>Hi {{username}}</h2>
<h3>Message to friend</h3>
<form action="http://localhost:8000/confirmEvent" method="POST">
{% csrf_token %}
<input type="hidden" name="id" value="{{eventStatusId}}">
<textarea name="message_to_friend"></textarea><br>
<input type="submit" value="I'LL BE THERE!!">
</form>
</body>
</html>
Письмо отправляется нормально, но при отправке его формы отображается эта ошибка:
Запрещено (403) Проверка CSRF не удалась. Запрос прерван.
Я не могу найти, как решить эту ошибку.
Я следовал многим ответам, подобным этим:
https://stackoverflow.com/a/10388110
Запретная (403) проверка CSRF не удалась. Запрос прерван. Даже при использовании {% csrf_token %}
без успеха.
Как я могу отправить форму внутри html-почты, избегая ошибки CSRF.
{% csrf_token %}
в вашей форме - person karthikr   schedule 31.07.2014