简体   繁体   English

Django:模板渲染期间出错

[英]Django: Error during template rendering

I am trying to build a feedback form but i am getting this error: Could not parse the remainder: '% csrf_token %' from '% csrf_token %' 我正在尝试建立反馈表,但出现此错误: 无法解析其余部分:'%csrf_token%'中的'%csrf_token%'

Here is my views.py: 这是我的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)

Here is my template contact.html: 这是我的模板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>

Typo there: 那里的错字:

Change this {{% csrf_token %}} to this {% csrf_token %} 将此{{% csrf_token %}}更改为此{% csrf_token %}

However, these kind of errors can easily be discovered by your side since Django's traceback is very detailed and points to the line of what caused the error. 但是,由于Django的回溯非常详细,并且指出了导致错误的原因,因此您可以很容易地发现此类错误。

Best regards! 最好的祝福!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM