Django中render_to_response和render的区别(转载)
2016-04-08 15:16
537 查看
转载地址:https://www.douban.com/note/278152737/
自django1.3开始:render()方法是render_to_response的一个崭新的快捷方式,前者会自动使用RequestContext。而后者必须coding出来,这是最明显的区别,当然前者更简洁。
return render_to_response('blog_add.html',{'blog': blog, 'form': form, 'id': id, 'tag': tag},
context_instance=RequestContext(request))
return render(request, 'blog_add.html', {'blog': blog, 'form': form, 'id': id, 'tag': tag})
locals()用法:locals()可以直接将函数中所有的变量全部传给模板。当然这可能会传递一些多余的参数,有点浪费内存的嫌疑。
return render(request, 'blog_add.html',locals())
自django1.3开始:render()方法是render_to_response的一个崭新的快捷方式,前者会自动使用RequestContext。而后者必须coding出来,这是最明显的区别,当然前者更简洁。
return render_to_response('blog_add.html',{'blog': blog, 'form': form, 'id': id, 'tag': tag},
context_instance=RequestContext(request))
return render(request, 'blog_add.html', {'blog': blog, 'form': form, 'id': id, 'tag': tag})
locals()用法:locals()可以直接将函数中所有的变量全部传给模板。当然这可能会传递一些多余的参数,有点浪费内存的嫌疑。
return render(request, 'blog_add.html',locals())
相关文章推荐
- 译:Google的大规模集群管理工具Borg(一)------ 用户视角的Borg特性
- Django1.4.2->Django1.6.1升级分享
- Mongo 保留字段的Collection的操作
- Got fatal error 1236 from master when reading data from binary log
- Maven使用Cargo实现自动化部署 - steveguoshao的专栏 - 博客频道 - CSDN.NET
- 谷歌离线地图API解析
- ajax.googleapis.com访问不了的解决
- Django项目--web聊天室
- Google Play应用商店开发者账号绑定信用卡(银行卡)
- django的模版
- Win7安装golang开发环境--备忘录
- djangosnippets: Diagram of your database structure
- algorithm@ Shortest Path in Directed Acyclic Graph (O(|V|+|E|) time)
- Django————模板
- swool作者rango的博客
- Django - Model graphic representation (ERD) - Stack Overflow
- Django开发 hello world
- Django中国社区 - 专注于Django中国技术发展的社区
- GoF——职责链模式
- Django REST framework教程一:序列化