https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/#render https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/#render
render(request, template[, dictionary][, context_instance][, content_type][, status][, current_app])
render()
是一个全新的捷径render_to_response
在1.3中会自动使用RequestContext
从现在开始我肯定会使用它。
2020 编辑:应该指出的是render_to_response()
在 Django 3.0 中被删除
https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/#render-to-response https://docs.djangoproject.com/en/1.8/topics/http/shortcuts/#render-to-response
render_to_response(template[, dictionary][, context_instance][, mimetype])¶
render_to_response
是教程等中使用的标准渲染函数。使用RequestContext
你必须指定context_instance=RequestContext(request)
https://docs.djangoproject.com/en/1.8/ref/generic-views/#django-views-generic-simple-direct-to-template https://docs.djangoproject.com/en/1.8/ref/generic-views/#django-views-generic-simple-direct-to-template
direct_to_template
是我在视图中使用的通用视图(而不是在我的网址中),因为就像新的render()
函数,它会自动使用RequestContext
及其所有的context_processor
s.
But direct_to_template
应该避免因为基于函数的通用视图已被弃用。要么使用render
或实际的课程,请参阅https://docs.djangoproject.com/en/1.3/topics/generic-views-migration/ https://docs.djangoproject.com/en/1.3/topics/generic-views-migration/
我很高兴我没有打字RequestContext
在很长很长的一段时间内。