来到这个页面的朋友可能大多是使用RequestContext(request)来生成csrf_token 以指望摆脱Forbidden(403)的吧?恭喜你,来对了地方。
在花了一天时间利用远古教学视频学习Django的时候遇到的问题。
其根本原因非常的……简单:Django更新了
简单的试了几下不行之后,就去看了官方文档,记录一下,现在是版本1.11.6,是2017年,21世纪。
文档地址:http://djx.readthedocs.io/en/stable/ref/templates/api.html?highlight=RequestContext#django.template.RequestContext
也不要花时间去看了,我把有用的搬运过来造福社会:
首先,是这个render_to_response方法:
render_to_response()
-
This function preceded the introduction of
render()
and workssimilarly except that it doesn’t make therequest
available in theresponse. It’s not recommended and is likely to be deprecated in the future.
render_to_response
(template_name, context=None, content_type=None, status=None, using=None)[source]