Django-render(),render_to_response()和direct_to_template()之间有什么区别?

Django-render(),render_to_response()和direct_to_template()之间有什么区别?,第1张

Django-render(),render_to_response()和direct_to_template()之间有什么区别?
render(request, template[, dictionary][, context_instance][, content_type][, status][, current_app])

render()
是一个
render_to_response
在1.3中崭新的快捷方式的品牌,该快捷方式将自动使用
RequestContext
,从现在开始我肯定会使用它。

render_to_response(template[, dictionary][, context_instance][, mimetype])¶

render_to_response
是教程等中使用的标准渲染功能。要使用
RequestContext
你必须指定
context_instance=RequestContext(request)

direct_to_template
是我在视图中使用的通用视图(而不是在URL中使用),因为像新
render()
功能一样,它会自动使用
RequestContext
及其所有
context_processor
s。

direct_to_template
应避免使用,因为不建议使用基于函数的通用视图。使用render还是实际使用的类,



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4980792.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-14
下一篇2022-11-14

发表评论

登录后才能评论

评论列表(0条)

    保存