• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
平日
博客园    首页    新随笔    联系   管理    订阅  订阅
三、模版的使用

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

    

 

posted on 2014-10-24 12:33  平日  阅读(837)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3