render_to_response() got an unexpected keyword argument 'context_instance'

来到这个页面的朋友可能大多是使用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()

render_to_response(template_name, context=None, content_type=None, status=None, using=None)[source]

This function preceded the introduction of render() and workssimilarly except that it doesn’t make the request available in theresponse. It’s not recommended and is likely to be deprecated in the future.

看到了吧,根本没有这个参数,而且最后一句说的很明白,这个垃圾函数人家不想伺候了。嗯推荐大家用render。不过也不要灰心,render和这个函数基本上是完全一样的,只是参数顺序不同而已。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值