django csrf解决办法
发布日期:2022-02-15 02:36:14 浏览次数:3 分类:技术文章

本文共 496 字,大约阅读时间需要 1 分钟。

原文出处:http://www.cppblog.com/momoxiao/archive/2011/10/03/157443.aspx?opt=admin
1 在 templete 中, 为每个 POST form 增加一个 {% csrf_token %} tag. 如下:
<form>
{% csrf_token %}
</form>
2 在 view 中, 使用 django.template.RequestContext 而不是 Context.
render_to_response, 默认使用 Context. 需要改成 RequestContext.
导入 class:
from django.template import RequestContext
给 render_to_response 增加一个参数:
def your_view(request):
...
return render_to_response('template.html',
your_key_value,
context_instance=RequestContext(request)
)

转载地址:https://blog.csdn.net/peterxiemin/article/details/84233078 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:三范式讲解
下一篇:c++模板学习一

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月14日 08时18分36秒