对django中render()与render_to_response()的区别详解

yipeiwu_com6年前Python基础

render()与render_to_response()均是django中用来显示模板页面的,但是在django1.3之后,render()便比render_to_response()更加招人待见!最明显的就是前者会自动使用RequestContext,而后者需要coding进去,

例如:

render(request,'share.html', {'registAdd': registAdd})
render_to_response('share.html',{'registAdd':registAdd},context_instance = RequestContext(request))

以上这篇对django中render()与render_to_response()的区别详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

对Python发送带header的http请求方法详解

简单的header import urllib2 request = urllib2.Request('http://example.com/') request.add_he...

Python Socket编程入门教程

这是用来快速学习 Python Socket 套接字编程的指南和教程。Python 的 Socket 编程跟 C 语言很像。 Python 官方关于 Socket 的函数请看 http:...

python中Switch/Case实现的示例代码

学习Python过程中,发现没有switch-case,过去写C习惯用Switch/Case语句,官方文档说通过if-elif实现。所以不妨自己来实现Switch/Case功能。 使用...

Python Property属性的2种用法

假设定义了一个类:C,该类必须继承自object类,有一私有变量_x 复制代码 代码如下: class C:  def __init__(self):   self.__x=None  ...

Python数据结构与算法之图的基本实现及迭代器实例详解

Python数据结构与算法之图的基本实现及迭代器实例详解

本文实例讲述了Python数据结构与算法之图的基本实现及迭代器。分享给大家供大家参考,具体如下: 这篇文章参考自《复杂性思考》一书的第二章,并给出这一章节里我的习题解答。 (这书不到12...