Django渲染方式
Reading Time:The full text has 139 words, estimated reading time: 1 minutes
Creation Date:2017-09-14
Previous Article:Django模板
Next Article:Django命令便查及设置
BEGIN
渲染方式
-
文本渲染: 直接通过函数HttpResponse返回字符串
- 引入:
from django.http import HttpResponse
- 返回:
return HttpResponse(string)
- 引入:
-
模板渲染:通过函数HttpResponse返回模板渲染后的页面
- 引入:
from django.http import HttpResponse
、from django.template.loader import get_template
- 渲染:
haha = '我是定义的变量,会在下面自动传到模板文件中替换' template = get_template('file_name.html') html = template.render(locals())
- 返回:
return HttpResponse(html)
- 引入:
-
模板渲染:通过函数render返回模板渲染后的页面
-
重定向:通过函数redirect实现页面重定向
- 引入:
from django.shortcuts import redirect
- 返回:
return redirect('url')
- 引入:
FINISH
Previous Article:Django模板
Next Article:Django命令便查及设置