最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python之django母板頁面的使用

 更新時間:2018年07月03日 08:16:32   作者:楓若雪  
這篇文章主要介紹了python之django母板頁面的使用,母版頁用于處理html頁面相同部分內(nèi)容,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

其實就是利用{% block xxx %}   {% endblock %}的方式定義一個塊,相當(dāng)于占位。存放在某個html中,比如base.html

然后在需要實現(xiàn)這些塊的文件中,使用繼承{% extends "base.html" %}的方式引入母板文件,然后在{% block xxx %}......{% endblock %}塊定義中實現(xiàn)具體的內(nèi)容。

base.html示例:注意塊的定義。

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- 上述3個meta標(biāo)簽*必須*放在最前面,任何其他內(nèi)容都*必須*跟隨其后! -->
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon"  rel="external nofollow" >
  <link rel="stylesheet"  rel="external nofollow" >
  <title>所有的書都在這里</title>
  {% block page_css %}
  {% endblock %}
  {% block page_js %}
  {% endblock %}

  <!-- Bootstrap core CSS -->
  <link  rel="external nofollow" rel="stylesheet">

  <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  <link  rel="external nofollow" rel="stylesheet">

  <!-- Custom styles for this template -->
  <link  rel="external nofollow" rel="stylesheet">

  <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
  <!--[if lt IE 9]><script src="http://v3.bootcss.com/assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
  <script src="http://v3.bootcss.com/assets/js/ie-emulation-modes-warning.js"></script>

  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
   <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
   <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>

<body>

{% include "nav.html" %}

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-3 col-md-2 sidebar">
      <ul class="nav nav-sidebar">
        <li class="{% block book_class %}{% endblock %}"><a href="/book_list/" rel="external nofollow" >所有的書 <span class="sr-only">(current)</span></a>
        </li>
        <li class="{% block publisher_class %}{% endblock %}"><a href="/publisher_list/" rel="external nofollow" >出版社</a></li>
        <li class="{% block author_class %}{% endblock %}"><a href="/author_list/" rel="external nofollow" >作者</a></li>

      </ul>
    </div>
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">      
      {% block main_body %}
        {#這里是每個頁面不同的部分#}
      {% endblock %}
    </div>
  </div>
</div>

<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="http://v3.bootcss.com/assets/js/vendor/jquery.min.js"><\/script>')</script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Just to make our placeholder images work. Don't actually copy the next line! -->
<script src="http://v3.bootcss.com/assets/js/vendor/holder.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="http://v3.bootcss.com/assets/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>

某個繼承頁:

{# 繼承母板 #}
{% extends 'base.html' %}

{% block book_class %}
  active
{% endblock %}
{% block page_css %}
  {% load static %}
  <link rel="stylesheet" href="{% get_static_prefix %}book_list_only.css" rel="external nofollow" >
{% endblock %}

{#把自己頁面的內(nèi)容,填入母板里面相應(yīng)的位置#}
{% block main_body %}
  <div class="panel panel-primary">
        <div class="panel-heading">
          <h3 class="panel-title">我是自定義內(nèi)容,用來替換母板中指定的位置</h3>
        </div>
        <div class="panel-body">
          <div class="row">
            <div class="col-md-8"> </div>
            <div class="col-md-4"><a href="/add_book/" rel="external nofollow" rel="external nofollow" class="btn btn-primary"><i class="fa fa-plus-square"></i> 添加新書</a>
              <a href="/add_publisher/" rel="external nofollow" rel="external nofollow" class="btn btn-success"><i class="fa fa-plus-square"></i> 添加出版社</a></div>
          </div>


          <table class="table table-dark table-hover">
            <thead>
            <tr>
              <th>#</th>
              <th>id</th>
              <th>名稱</th>
              <th>出版社</th>
              <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {% for b in books %}
              <tr>
                <td>{{ forloop.counter }}</td>
                <td>{{ b.id }}</td>
                <td>{{ b.title }}</td>
                <td>{{ b.publisher.name }}</td>
                <td>
                  <a href="/del_book/?id={{ b.id }}" rel="external nofollow" class="btn btn-danger"><i class="fa fa-trash fa-fw"></i>刪除</a>
                  <a href="/edit_book/?id={{ b.id }}" rel="external nofollow" class="btn btn-info"><i class="fa fa-pencil fa-fw"></i>編輯</a>
                </td>
              </tr>
            {% endfor %}
            </tbody>
          </table>

        </div>
      </div>
{% endblock %}

另一個繼承頁:

{% extends "base.html" %}
{% block main_body %}
      <div class="panel panel-primary">
        <div class="panel-heading">
          <h3 class="panel-title">所有的出版社</h3>
        </div>
        <div class="panel-body">
          <div class="row">
            <div class="col-md-8"> </div>
            <div class="col-md-4"><a href="/add_book/" rel="external nofollow" rel="external nofollow" class="btn btn-primary"><i class="fa fa-plus-circle fa-fw"></i>添加新書</a>
              <a href="/add_publisher/" rel="external nofollow" rel="external nofollow" class="btn btn-success"><i class="fa fa-plus-circle fa-fw"></i>添加出版社</a></div>
          </div>


          <table class="table table-dark table-hover">
            <thead>
            <tr>
              <th>#</th>
              <th>id</th>
              <th>名稱</th>
              <th>地址</th>
              <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {% for p in publisher %}
              <tr>
                <td>{{ forloop.counter }}</td>
                <td>{{ p.id }}</td>
                <td>{{ p.name }}</td>
                <td>{{ p.addr }}</td>
                <td>
                  <a href="/del_publisher/?id={{ p.id }}" rel="external nofollow" class="btn btn-danger"><i class="fa fa-remove fa-fw"></i>刪除</a>
                  <a href="/edit_publisher/?id={{ p.id }}" rel="external nofollow" class="btn btn-info"><i class="fa fa-edit fa-fw"></i>編輯</a>
                </td>
              </tr>
            {% endfor %}
            </tbody>
          </table>

        </div>
      </div>
 {% endblock %}
{% block publisher_class %}
  active
{% endblock %}

完整的練習(xí)項目代碼:day63_base_jb51.rar

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python實現(xiàn)根據(jù)IP地址和子網(wǎng)掩碼算出網(wǎng)段的方法

    Python實現(xiàn)根據(jù)IP地址和子網(wǎng)掩碼算出網(wǎng)段的方法

    這篇文章主要介紹了Python實現(xiàn)根據(jù)IP地址和子網(wǎng)掩碼算出網(wǎng)段的方法,涉及Python基于Linux平臺的字符串操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-07-07
  • 計算機(jī)二級python學(xué)習(xí)教程(2) python語言基本語法元素

    計算機(jī)二級python學(xué)習(xí)教程(2) python語言基本語法元素

    這篇文章主要為大家詳細(xì)介紹了計算機(jī)二級python學(xué)習(xí)教程的第2篇,Python語言基本語法元素,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • Python通過cv2讀取多個USB攝像頭

    Python通過cv2讀取多個USB攝像頭

    這篇文章主要為大家詳細(xì)介紹了Python通過cv2讀取多個USB攝像頭,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • Python pandas的describe函數(shù)參數(shù)示例詳解

    Python pandas的describe函數(shù)參數(shù)示例詳解

    describe()函數(shù)是pandas 中一個十分實用的工具,用于快速獲取數(shù)據(jù)集的描述性統(tǒng)計信息,本文詳細(xì)介紹了該函數(shù)的各種參數(shù)及其用法,包括控制輸出的百分位數(shù)、列類型以及是否將日期時間列視為數(shù)值型列等,感興趣的朋友一起看看吧
    2018-04-04
  • Python爬蟲實現(xiàn)搭建代理ip池

    Python爬蟲實現(xiàn)搭建代理ip池

    這篇文章主要介紹了Python爬蟲實現(xiàn)搭建代理ip池,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下,希望對你的工作有所幫助
    2022-06-06
  • 對python while循環(huán)和雙重循環(huán)的實例詳解

    對python while循環(huán)和雙重循環(huán)的實例詳解

    今天小編就為大家分享一篇對python while循環(huán)和雙重循環(huán)的實例詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • Pytorch 擴(kuò)展Tensor維度、壓縮Tensor維度的方法

    Pytorch 擴(kuò)展Tensor維度、壓縮Tensor維度的方法

    這篇文章主要介紹了Pytorch 擴(kuò)展Tensor維度、壓縮Tensor維度的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • 計算pytorch標(biāo)準(zhǔn)化(Normalize)所需要數(shù)據(jù)集的均值和方差實例

    計算pytorch標(biāo)準(zhǔn)化(Normalize)所需要數(shù)據(jù)集的均值和方差實例

    今天小編就為大家分享一篇計算pytorch標(biāo)準(zhǔn)化(Normalize)所需要數(shù)據(jù)集的均值和方差實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • Python繪圖之自定義圖類型控件實現(xiàn)混合類型圖表

    Python繪圖之自定義圖類型控件實現(xiàn)混合類型圖表

    這篇文章主要為大家詳細(xì)介紹了Python如何新建繪圖類型控件,實現(xiàn)混合類型圖表,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-08-08
  • Python lambda匿名函數(shù)深入講解

    Python lambda匿名函數(shù)深入講解

    lambda所表示的匿名函數(shù)的內(nèi)容應(yīng)該是很簡單的,如果復(fù)雜的話,干脆就重新定義一個函數(shù)了,使用lambda就有點過于執(zhí)拗了。lambda就是用來定義一個匿名函數(shù)的,如果還要給他綁定一個名字的話,就會顯得有點畫蛇添足,通常是直接使用lambda函數(shù)
    2023-01-01

最新評論

临夏市| 莒南县| 舞钢市| 波密县| 缙云县| 仁寿县| 理塘县| 健康| 镇平县| 万年县| 沭阳县| 犍为县| 互助| 无棣县| 景宁| 敖汉旗| 永修县| 北流市| 马关县| 图木舒克市| 平和县| 邵阳县| 东兴市| 全州县| 正镶白旗| 金昌市| 双柏县| 云梦县| 巩义市| 阳原县| 渭源县| 曲麻莱县| 和龙市| 东丰县| 泰兴市| 邵武市| 类乌齐县| 巴彦淖尔市| 望奎县| 涿鹿县| 永平县|