一、模板样式

注意:

1、url

urlpatterns = {
path('admin/', admin.site.urls),
path('order/', views.order),
path('shopping_car/', views.shopping_car),
}

2、views

from django.shortcuts import render, render_to_response, redirect
from django.http import HttpResponse
import datetime
from blog import models def order(req): return render(req,"order.html") def shopping_car(req): return render(req,"shopping_car.html")

3、templates

1)order

<!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: 15%;
}
.page-body .content{
height: 500px;
background-color: cornflowerblue;
float: left;
width: 85%;
}
.page-footer{
height: 30px;
background-color: darkblue;
clear: both;
}
</style>
</head>
<body>
<div>
<div class="page-header"></div>
<div class="page-body">
<div class="menu">
<a href="/order/">订单</a><br>
<a href="/shoping_car/">购物车</a>
</div>
<div class="content">订单</div> </div>
<div class="page-footer"></div>
</div>
</body>
</html>

2)shopping_car

<!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: 10%;
}
.page-body .content{
height: 500px;
background-color: cornflowerblue;
float: left;
width: 90%;
}
.page-footer{
height: 30px;
background-color: darkblue;
clear: both;
}
</style>
</head>
<body>
<div>
<div class="page-header"></div>
<div class="page-body">
<div class="menu">
<a href="/order/">订单</a><br>
<a href="/shoping_car/">购物车</a>
</div>
<div class="content"> 购物车</div> </div>
<div class="page-footer"></div>
</div>
</body>
</html>

二、引入模板

注意:

1)设置模板--非公共部分使用此种方法代替

{% block content %}

{% endblock %}

2)引入模板

extends引入模板

{% block content %}包含私有部分

{% extends "base.html" %}
{% block content %}
<div class="content">订单</div>
{% endblock %}

1、url

urlpatterns = {
path('admin/', admin.site.urls),
# path('cur_time/', views.cur_time),
# # path('userInfo/',views.userInfo),
# path('login/', views.login),
# path('home/', views.home),
# path('hello/',views.hello),
path('order/', views.order),
path('shopping_car/', views.shopping_car),
}

2、views

from django.shortcuts import render, render_to_response, redirect
from django.http import HttpResponse
import datetime
from blog import models def order(req): return render(req,"order.html") def shopping_car(req): return render(req,"shopping_car.html")

3、templates

1)base

<!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: 15%;
}
.page-body .content{
height: 500px;
background-color: cornflowerblue;
float: left;
width: 85%;
}
.page-footer{
height: 30px;
background-color: darkblue;
clear: both;
}
</style>
</head>
<body>
<div>
<div class="page-header"></div>
<div class="page-body">
<div class="menu">
<a href="/order/">订单</a><br>
<a href="/shoping_car/">购物车</a>
</div>
{% block content %} {% endblock %} </div>
<div class="page-footer"></div>
</div>
</body>
</html>

2)order

{% extends "base.html" %}
{% block content %}
<div class="content">订单</div>
{% endblock %}

3)shopping_car

{% extends "base.html" %}
{% block content %}
<div class="content"> 购物车</div>
{% endblock %}

三、展示效果

点击订单或者购物车,行营的url链接、右边显示的内容随之改变

Python Django 之 Template 模板的使用的更多相关文章

  1. Python Django 之 Template 模板语言简介

    一.什么事模板语言 html+逻辑控制语句 二.模板语言的作用 帮助前端处理后端发来的数据,方便前端展示(杂糅渲染) 三.模板语言语法 1.{{变量}} 变量使用双大括号{{}} 2.万能的句点号. ...

  2. python Django教程 之模板渲染、循环、条件判断、常用的标签、过滤器

    python3.5 manage.py runserver python Django教程 之模板渲染.循环.条件判断.常用的标签.过滤器 一.Django模板渲染模板 1. 创建一个 zqxt_tm ...

  3. python - django 解决 templates 模板语言语法冲突

    # 在使用某个框架时发现语法与Django的模板语法冲突了,于是找到解决方案: {% verbatim %} // 被 verbatim 包裹起来的地方是不会被 django 渲染的 {% endve ...

  4. python框架Django中MTV框架之Template(模板/界面)

    MTV框架之Template(模板/界面) 关注公众号"轻松学编程"了解更多. 1.模板目录位置 应用下 不需要注册 无法跨应用地进行复用 工程下 需要注册 settings.py ...

  5. Python Web框架篇:Django templates(模板)

    为什么用templates? views.py视图函数是用来写Python代码的,HTML可以被直接硬编码在views.py之中.如下: import datetime def current_tim ...

  6. Python Django框架笔记(六):模板

    (一){%%}和{{ }} {% for post in posts %} <a href=""><h2>{{ post.title }}</h2&g ...

  7. Python菜鸟之路:Django 路由、模板、Model(ORM)

    Django路由系统 Django的路由系统让Django可以根据URI进行匹配,进而发送至特定的函数去处理用户请求.有点类似nginx的location功能. Django的路由关系分为三种:普通关 ...

  8. django基础2: 路由配置系统,URLconf的正则字符串参数,命名空间模式,View(视图),Request对象,Response对象,JsonResponse对象,Template模板系统

    Django基础二 request request这个参数1. 封装了所有跟请求相关的数据,是一个对象 2. 目前我们学过1. request.method GET,POST ...2. reques ...

  9. python :Django url /views /Template 文件介绍

    1,Django URL 路由系统 URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL模式以及要为该URL模式调用的视图函数之间的映射表:你就是以这种方式告诉Django ...

随机推荐

  1. 01-python基础知识

    1.这两个参数是什么意思:*args,**kwargs?我们为什么要使用它们? 答案 如果我们不确定要往函数中传入多少个参数,或者我们想往函数中以列表和元组的形式传参数时,那就使要用*args:如果我 ...

  2. [MySQL]典型的行列转换

    列变成行 测试数据库数据样式: 应用的sql语句: SELECT TM,NAME,SUM(GE) AS 'GE',SUM(GD) AS 'GD',SUM(CT) AS 'CT',SUM(NUM) AS ...

  3. win10 java环境变量

    https://jingyan.baidu.com/article/fd8044fa2c22f15031137a2a.html

  4. spring cloud: zuul(四): 正则表达式匹配其他微服务(给其他微服务加版本号)

    spring cloud: zuul(四): 正则表达式匹配其他微服务(给其他微服务加版本号) 比如我原来有,spring-boot-user微服务,后台进行迭代更新,另外其了一个微服务: sprin ...

  5. xsd与xml和类(class)对象之间的互相转换

    xsd与xml和类(class)对象之间的互相转换 . 第一:通过现有的已经写好的xsd来生成class(.cs)文件. 在您Visual Studio的安装目录下的SDKv2.0Bin中有个应用程序 ...

  6. 恶意代码分析-使用apataDNS+inetsim模拟网络环境

    准备工作 虚拟机安装: Win7 Ubuntu apateDNS 密码:wplo inetsim 密码:ghla 客户端Win7需要做的工作 安装apateDNS 服务器端Ubuntu需要做的工作 下 ...

  7. LeetCode--496--下一个更大元素I(java)

    给定两个没有重复元素的数组 nums1和 nums2 ,其中nums1 是 nums2 的子集.找到 nums1 中每个元素在 nums2 中的下一个比其大的值. nums1 中数字 x 的下一个更大 ...

  8. HDOJ 1023 Train Problem II

    考虑第1个火车出站的时刻,从1到n都有可能,如果它是第i个出栈,那么前面有规模为i-1的子问题,后面有规模为n-i的子问题.累加.

  9. yarn hadoop-2.3.0 installation cluster Centos 64bits

    Apache Hadoop -2.2.0 - How to Install a Three Nodes Cluster http://tonylixu.blogspot.ca/2014/02/apac ...

  10. Confluence 6 如何保持我空间的整洁

    如果你有很多用户在同一个空间中编辑和创建内容,你的空间将会很快的变得混乱不堪.你可以使用下面的一些步骤来避免这个的发生. 创建一系列的指南 让你的合作编辑用户知道创建页面的上级页面是什么,这样可以保证 ...