我收到错误消息“CSRF 令牌丢失或不正确”,但我相信我在模板中包含了正确的标签。以下是显示此错误的视图和模板:
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
return HttpResponseRedirect('/contact/thanks/')
else:
form = ContactForm()
return render_to_response('reserve/templates/contact_form.html',{'form': form})
模板:
<html>
<head>
<title>Contact us</title>
</head>
<body>
<h1>Contact us</h1>
{% if form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}
<form action="" method="post">
{% csrf_token %}
<table>
{{ form.as_p }}
</table>
<input type="submit" value="Submit">
</form>
</body>
</html>