render与render_to_response
def render_to_response(template_name, context=None, content_type=None, status=None, using=None):
    content = loader.render_to_string(template_name, context, using=using)
    return HttpResponse(content, content_type, status)
def render(request, template_name, context=None, content_type=None, status=None, using=None):
    content = loader.render_to_string(template_name, context, request, using=using)
    return HttpResponse(content, content_type, status)
这两个快捷函数都是内部调用了django.template.loader.render_to_string函数,
返回的HTML内容文本给response。
这两个函数之间的区别就在于是否传入request对象,其实传入的context上下文最终传入render_to_string中,然后获取选择模板对象,然后模板对象调用其render函数,再次传入context上下文对象,插入模板返回一系列HTML文本字符串。
最后这些字符串向外传递给(feed into)HTTPResponse对象,快捷返回的是HTTPResponse对象。
render_to_string中有两个重要的函数被调用就是get_template和select_template,通过模板引擎来获取模板对象。

最新文章

  1. UI第十九节——UICollectionView
  2. 转载:AbstractQueuedSynchronizer的介绍和原理分析
  3. dojo grid 编辑问题
  4. 【转载】谷歌酝酿将苹果Swift作为安卓APP主要开发语言
  5. [转]关于jquery中html()、text()、val()的区别
  6. JS适配问题。
  7. c# App.Config详解
  8. eclipse下导入工程的小问题
  9. DirectX 绘制
  10. 在Android上使用Google V8 JS 引擎
  11. Fragment inner class should be static
  12. ASP.NET 4.0 来了
  13. iOS 获取项目名称及版本号
  14. git:hook declined FATAL: W refs/heads DENIED by fallthru error
  15. C / C++算法学习笔记(8)-SHELL排序
  16. JavaScript for in的缺陷
  17. [LeetCode] Score of Parentheses 括号的分数
  18. #6 ipdb模块源代码解读
  19. 劳德巴赫下载kernel和文件系统时问题
  20. 4面向对象(OOP)

热门文章

  1. 用NIO实现http协议
  2. nginx反向代理cas server之1:多个cas server负载均衡配置以及ssl配置
  3. 常见浏览器的宽高代码写法!有原生JavaScript和jquery两种写法-------------------------------以及我的个人网站
  4. centos5.5下mangodb启动报错glibc
  5. .NET Framework 各个版本介绍
  6. mysql 发生系统错误 1067
  7. 【CC2530入门教程-03】CC2530的中断系统及外部中断应用
  8. Streaming结合Kafka
  9. Spring Boot 集成swagger实例
  10. 分享一款简单好用的HTML拼接工具