django之创建第3个项目:编写第一个模板文件

1、django结构

2、在站点blog下创建templates文件夹,专门用于存放模板文件

3、在templates文件夹下创建index.html文件

  #index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>第一个模板文件</title>
</head>
<body>
    <h1>django之创建第三个项目:编写第一个模板文件</h1>
</body>
</html>

4、修改views.py文件

# Create your views here.
#coding:utf-8
from django.http import HttpResponse

#导入templates文件所需导入库,注意没有s
from django.template import loader,Context

def index(request):
    #第二个项目
    #return HttpResponse("hello,Django")


    #加载器,获取一个模板
    t=loader.get_template("index.html")
    c=Context({})#没有写入数据,只是单纯的加载了index.html文件
    return HttpResponse(t.render(c))
原文地址:https://www.cnblogs.com/dengyg200891/p/5352941.html