1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python的render参数_django中render_to_response的可选参数和使用方法

python的render参数_django中render_to_response的可选参数和使用方法

时间:2018-07-18 09:32:51

相关推荐

python的render参数_django中render_to_response的可选参数和使用方法

在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(

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。