美文网首页
centos7搭建django简单上线.6--使用模板html和

centos7搭建django简单上线.6--使用模板html和

作者: Kevin0is0me | 来源:发表于2019-05-26 12:56 被阅读0次

1.在项目目录下新建一个templates目录,在templates目录下新建一个booktest目录,再新建一个index.html

然后在setting.py中设置模板的路径

如图所示:

2.定义模板

打开templtes/booktest/index.html文件,定义代码如下:

<html>

<head>

    <title>图书列表</title>

</head>

<body>

<h1>{{title}}</h1>

{%for i in list%}

{{i}}<br>

{%endfor%}

</body>

</html>

3.打开booktst/views.py文件,写以下代码:

from django.shortcuts import render

def index(request):

    context={'title':'图书列表','list':range(10)}

    return render(request,'booktest/index.html',context)

4.效果

相关文章

网友评论

      本文标题:centos7搭建django简单上线.6--使用模板html和

      本文链接:https://www.haomeiwen.com/subject/ssvxtctx.html