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",{})

    

 

相关文章:

  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2021-08-30
  • 2022-01-20
  • 2022-12-23
猜你喜欢
  • 2021-05-19
  • 2022-12-23
  • 2021-05-15
  • 2022-12-23
  • 2022-01-05
  • 2021-08-10
相关资源
相似解决方案