【模板查找路径】

如下图,在setting.py中TEMPLATES内,DIRS为模板查找的目录,APP_DIRS为True表示INSTALLED_APPS中APP目录下的temlates。先查找DIRS内容在查找ADD_DIRS内容

【得到模板渲染HttpResponse结果】

render(requesttemplate_namecontext=Nonecontent_type=Nonestatus=Noneusing=None)

from django.shortcuts import render

返回一个HttpResponse 对象

request:视图参数

template_name:字符串,模板名字,在查找路径查找

context:用例渲染模板的内容,可用locals()讲返回视图函数局部变量

【得到模板渲染内容】

render_to_string(template_namecontext=Nonerequest=Noneusing=None)

from django.template.loader import render_to_string

返回字符串对象,可用该方法用于页面动态部分变化,返回前台将相关内容替换。

template_name:字符串,模板名字,在查找路径查找

context:用例渲染模板的内容,可用locals()讲返回视图函数局部变量