0
我想建立一個反饋表,但我得到這個錯誤時出錯: 無法解析餘數爲:「%csrf_token%」從「%csrf_token%」Django的:模板渲染
這裏我的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,
['[email protected]']
)
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中這是一個很好的做法。 –
我很抱歉延遲接受你的答案。謝謝... –