2017-03-18 151 views
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> 
+0

如果此答案幫助您將其標記爲已接受。在StackOverflow中這是一個很好的做法。 –

+0

我很抱歉延遲接受你的答案。謝謝... –

回答

5

錯字有:

更改此{{% csrf_token %}}{% csrf_token %}

然而,這些樣的錯誤可以很容易地在你身邊發現的,因爲Django的回溯,非常詳細,點的是什麼導致錯誤的行。

此致敬禮!

+0

哦是的:),非常感謝.... –