您的位置:首页 > 编程语言 > Go语言

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

2016-04-04 21:12 525 查看
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))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: