Table of Contents:
  1. 渲染方式

    Django渲染方式

    Reading Time:The full text has 139 words, estimated reading time: 1 minutes
    Creation Date:2017-09-14
    Article Tags:
    Previous Article:Django模板
     
    BEGIN

    渲染方式

    1. 文本渲染: 直接通过函数HttpResponse返回字符串

      • 引入:from django.http import HttpResponse
      • 返回:return HttpResponse(string)
    2. 模板渲染:通过函数HttpResponse返回模板渲染后的页面

      • 引入:from django.http import HttpResponsefrom django.template.loader import get_template
      • 渲染:
        haha = '我是定义的变量,会在下面自动传到模板文件中替换'
        template = get_template('file_name.html')
        html = template.render(locals())
      • 返回:return HttpResponse(html)
    3. 模板渲染:通过函数render返回模板渲染后的页面

    4. 重定向:通过函数redirect实现页面重定向

      • 引入:from django.shortcuts import redirect
      • 返回:return redirect('url')
    FINISH
    Previous Article:Django模板

    Random Articles
    Life Countdown
    default