Django模板繼承 extend標簽實例代碼詳解
更新時間:2019年05月16日 12:01:56 作者:klvchen
這篇文章主要介紹了Django模板繼承 extend標簽實例代碼,非常不錯,具有一定的參考借鑒價值 ,需要的朋友可以參考下
在 views.py 上修改
... def ordered(req): return render(req, "ordered.html") def shopping_car(req): return render(req, "shopping_car.html")
在 urls.py 上修改
...
path('ordered/', views.ordered),
path('shopping_car/', views.shopping_car),
...
在 tmplates 文件夾下創(chuàng)建 base.html 文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.page-header{
height:50px;
background-color: rebeccapurple;
}
.page-body .menu{
height: 500px;
background-color: antiquewhite;
float: left;
width: 20%;
}
.page-body .content{
height: 500px;
background-color: cornflowerblue;
float: left;
width: 80%
}
.page-footer{
height:50px;
background-color: green;
clear: both;
}
</style>
</head>
<body>
<div>
<div class="page-header"></div>
<div class="page-body">
<div class="menu">
<a href="/ordered/" rel="external nofollow" >訂單</a><br>
<a href="/shopping_car/" rel="external nofollow" >購物車</a>
</div>
{% block content %}
{% endblock %}
</div>
<div class="page-footer"></div>
</div>
</body>
</html>
ordered.html 文件
{% extends "base.html" %}
{% block content %}
<div class="content">
訂單
</div>
{% endblock %}
shopping_car.html 文件
{% extends "base.html" %}
{% block content %}
<div class="content">
購物車
</div>
{% endblock %}
效果如下:

總結(jié)
以上所述是小編給大家介紹的Django模板繼承 extend標簽實例代碼詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
微信小程序自定義頭部導航欄和導航欄背景圖片 navigationStyle問題
這篇文章主要介紹了微信小程序 自定義頭部導航欄和導航欄背景圖片 navigationStyle功能,本文給大家介紹的非常詳細,具有一定的參考借鑒價值 ,需要的朋友可以參考下2019-07-07
Bootstrap導航菜單點擊后無法自動添加active的處理方法
今天小編就為大家分享一篇Bootstrap導航菜單點擊后無法自動添加active的處理方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
拖動Html元素集合 Drag and Drop any item
拖動Html元素集合 Drag and Drop any item...2006-12-12

