【发布时间】:2017-03-18 09:36:22
【问题描述】:
我正在尝试构建反馈表,但出现此错误: 无法解析余数:'% csrf_token %' from '% csrf_token %'
这是我的views.py:
def contact(request):
if request.method=='POST':
form=ContactForm(request.POST)
if form.is_valid():
topic=form.cleaned_data['topic']
message=form.cleaned_data['message']
sender=form.cleaned_data.get('sender')
send_mail(
'Feedback from your site,topic:%s'%topic,
message,
sender,
['jpahultiwari@gmail.com']
)
return HttpResponseRedirect('/contact/thanks/')
else:
form=ContactForm()
context={'form':form}
return render(request,'blog/contact.html',context)
这是我的模板contact.html:
<!DOCTYPE html>
<html>
<head>
<title>Feedback Form</title>
</head>
<body>
<h1>Contact Us</h1>
<form action="." method="post" >
{{% csrf_token %}}
<table>{{form.as_table}}</table>
<p><input type="submit" value="Submit"></p>
</form>
</body>
</html>
【问题讨论】:
-
如果此答案帮助您将其标记为已接受。在 StackOverflow 中这样做是一个很好的做法。
-
很抱歉延迟接受您的回答。谢谢...
标签: python django django-templates