当前位置:   article > 正文

python Django render()函数使用祥解

django render
  1. from django.shortcuts import render  
  2.    
  3. def hello(request):  
  4.     context = {}  
  5.     context['hello'] = 'Hello World!'  
  6.     return render(request, 'hello.html', context)  
  7.    #return render(request, 'hello.html', {'hello':'Hello World!'})



render()函数传递context来填充模板
help文档中render描述
render(request, template_name, context=None, content_type=None, status=None, using=None)

参数:

request: 是一个固定参数

template_name: templates中定义的文件,注意路径名。比如:“templates/polls/index.html”, 则参数这样写:“polls/index.html”

context: 要传入文件中用于渲染呈现的数据, 默认是字典格式
content_type: 生成的文档要使用的MIME 类型。默认为DEFAULT_CONTENT_TYPE 设置的值。
status: http的响应代码,默认是200.
using: 用于加载模板使用的模板引擎的名称。
————————————————
版权声明:本文为CSDN博主「yoyo_573」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/yoyo_573/article/details/108344720

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/390443
推荐阅读
相关标签
  

闽ICP备14008679号