1、创建模版文件
首先在Blog下创建templates文件夹
在里面新建一个index.html
内容如下
<pre>
<!DOCTYPE html>
<html><head><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta property="wb:webmaster" content="404d6a11b9f5a1be"/> <meta property="qc:admins" content="12423717776137740556375"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><title>django study</title></head><body><h1>welcome to my website,this is first!</h1></body></html><pre>
2、找到blog/views.py有2种方式修改
1)
新增引用 from django.template import loader,Context
把def里内容修改一下
def index(req):
t=loader.get_template("index")
c=Context({})
return HttpResponse(t.render(c))
2)
把views.py内容清空
引入from django_shortcuts import render_to_response
def index(req):
return render_to_response("index.html",{})