有谁知道为什么以下渲染我的模板确定:CSRF令牌不若使用上下文({字典})VS只是{字典}呈现
c= {'render_form' : form }
return render(request, 'page1.html', c)
但下面不会使CSRF令牌:
c= Context({'render_form' : form})
return render(request, 'page1.html', c)
模板看起来是这样的:
<form method="post">
{% csrf_token %}
{{ render_form }}
<input type="submit" value="Submit" class='btn' id="submitbutton" name="_submit" />
</form>
我想保持render()
,我想一个无效使用locals()
。
我不明白你为什么会使用右键明确不过。只要通过一本字典,那就是你应该做的。 –
我以为我应该。我试图按照https://docs.djangoproject.com/en/1.8/ref/templates/api/#playing-with-context中的示例进行操作。我只会坚持那个有效的方法。 – woodduck