在django官方文档中有比较详细的介绍,在此我按照自己的理解适当的阐述一下:
returnrender_to_response(①my_template.html,
②my_data_dictionary,
③context_instance=RequestContext(request)
)
①template_name
毫无疑问这个就是你要渲染的模板的路径下的模板名,(一个.html文件),注意:这个参数是必须要求有的,假如没有的话是会报错的。
(官方文档阐述:The full name of a template to use or sequence of template names. If a sequence is given, the first templa
te that exists will be used)
②my_data_dictionary
这是一个字典(python dict),字典中的值添加到模板上下文,默认情况下这个字典是空的,如果调用这个模板中的值,你的模板将会
被视图函数渲染。
③context_instance=RequestContext(request)在使用render_to_response,render_to_string等shortcut的时候,可以附带context_instance参数
来使用RequestContext:
def some_view(request):
... return render_to_response(my_template.html,
my_data_dictionary, context_instance=RequestContext(