HttpResponse render render_to_response 三者的区别

HttpResponse("

Here's the text of the Web page.

") 服务器直接返回一段字符串给客户端浏览器
或者用它返回一个文件HttpResponse(json_str, content_type='application/json; charset=utf-8')

render render_to_response
这里的render()不是django.template的t.render(),而是最近Django版本新增的django.shortcuts.render(),类似django.shortcuts.render_to_response(),但这个render()是用来替代render_to_response(),
官方文档关于render的说明

官方文档关于render_to_response的说明提到,

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

不建议再用render_to_response,用render代替。
render默认要求带入request,虽然render_to_response也可以用RequestContext将request参数带入。

转载于:https://www.cnblogs.com/lightwind/p/6038350.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值