python Django render()函数使用祥解

from django.shortcuts import render  
   
def hello(request):  
    context = {}  
    context['hello'] = 'Hello World!'  
    return render(request, 'hello.html', context)  
   #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

猜你喜欢

转载自blog.csdn.net/davice_li/article/details/131766104