Django使用 Bootstrap 样式修改书籍列表过程解析


Posted in Python onAugust 09, 2019

展示书籍列表:

首先修改原先的 book_list.html 的代码:

<!DOCTYPE html>
<!-- saved from url=(0042)https://v3.bootcss.com/examples/dashboard/ -->
<html lang="zh-CN">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="https://v3.bootcss.com/favicon.ico" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 
  <title>书籍列表管理</title>
  <!-- Bootstrap core CSS -->
  <link href="/static/bootstrap/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">
  <!-- Custom styles for this template -->
  <link href="/static/dashboard.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">
  <link rel="stylesheet" href="/static/fontawesome/css/font-awesome.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
</head>
 
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
          aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="https://v3.bootcss.com/examples/dashboard/#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >图书管理系统</a>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav navbar-right">
        <li><a href="https://v3.bootcss.com/examples/dashboard/#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Dashboard</a></li>
        <li><a href="https://v3.bootcss.com/examples/dashboard/#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Settings</a></li>
        <li><a href="https://v3.bootcss.com/examples/dashboard/#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Profile</a></li>
        <li><a href="https://v3.bootcss.com/examples/dashboard/#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Help</a></li>
      </ul>
      <form class="navbar-form navbar-right">
        <input type="text" class="form-control" placeholder="Search...">
      </form>
    </div>
  </div>
</nav>
 
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-3 col-md-2 sidebar">
      <!-- active 表示当前页面,会加亮 -->
      <ul class="nav nav-sidebar">
        <li><a href="/publisher_list/" rel="external nofollow" >出版社列表页</a></li>
        <li class="active"><a href="/book_list/" rel="external nofollow" >书籍列表</a></li>
        <li><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">
      <h1 class="page-header">书籍管理页面</h1>
 
      <div class="panel panel-primary">
        <!-- Default panel contents -->
        <div class="panel-heading">书籍列表 <i class="fa fa-thumb-tack pull-right"></i></div>
        <div class="panel-body">
          <div class="row" style="margin-bottom: 15px">
            <div class="col-md-4">
              <div class="input-group">
                <input type="text" class="form-control" placeholder="Search for...">
                <span class="input-group-btn">
                  <button class="btn btn-default" type="button">搜索</button>
                </span>
              </div><!-- /input-group -->
            </div><!-- /.col-md-4 -->
            <!-- 跳转到另一页面,添加新的书籍 -->
            <div class="col-md-1 pull-right">
              <a href="/add_book/" rel="external nofollow" class="btn btn-success">新增</a>
            </div>
 
          </div><!-- /.row -->
 
          <table class="table table-bordered">
            <thead>
            <tr>
              <th>#</th>
              <th>id</th>
              <th>书名</th>
              <th>出版社名称</th>
              <th>操作</th>
            </tr>
            </thead>
            <!-- 从原先的 book_list.html 拷贝过来的代码-->
            <tbody>
            {% for book in book_list %}
              <tr>
                <td>{{ forloop.counter }}</td>
                <td>{{ book.id }}</td>
                <td>{{ book.title }}</td>
                <td>{{ book.publisher.name }}</td>
                <td>
                  <a class="btn btn-danger" href="/del_book/?id={{ book.id }}" rel="external nofollow" >删除</a>
                  <a class="btn btn-info" href="/edit_book/?id={{ book.id }}" rel="external nofollow" >编辑</a>
                </td>
              </tr>
            {% endfor %}
            </tbody>
          </table>
 
          <nav aria-label="Page navigation" class="text-right">
            <ul class="pagination">
              <li>
                <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" aria-label="Previous">
                  <span aria-hidden="true">«</span>
                </a>
              </li>
              <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >1</a></li>
              <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2</a></li>
              <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >3</a></li>
              <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4</a></li>
              <li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >5</a></li>
              <li>
                <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" aria-label="Next">
                  <span aria-hidden="true">»</span>
                </a>
              </li>
            </ul>
          </nav>
        </div>
 
      </div>
    </div>
  </div>
</div>
 
 
<div class="modal fade" tabindex="-1" role="dialog" id="myModal">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
        </button>
        <h4 class="modal-title">用户信息</h4>
      </div>
      <div class="modal-body">
        <form class="form-horizontal">
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">邮箱</label>
            <div class="col-sm-10">
              <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
            </div>
          </div>
          <div class="form-group">
            <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
            <div class="col-sm-10">
              <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
            </div>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-primary">保存</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
 
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="/static/jquery-3.3.1.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
 
</body>
</html>

修改过程:

Django使用 Bootstrap 样式修改书籍列表过程解析

Django使用 Bootstrap 样式修改书籍列表过程解析

Django使用 Bootstrap 样式修改书籍列表过程解析

运行效果:

Django使用 Bootstrap 样式修改书籍列表过程解析

添加书籍:

再来修改 add_book.html

<!DOCTYPE html>
<!-- saved from url=(0042)https://v3.bootcss.com/examples/dashboard/ -->
<html lang="zh-CN">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="https://v3.bootcss.com/favicon.ico" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 
  <title>添加书籍</title>
  <!-- Bootstrap core CSS -->
  <link href="/static/bootstrap/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">
  <!-- Custom styles for this template -->
  <link href="/static/dashboard.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">
  <link rel="stylesheet" href="/static/fontawesome/css/font-awesome.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
</head>
<!-- 以上 head 部分从 book_list.html 赋值过来并加以修改 -->
 
<!-- 以下 body 部分可从 Bootstrap 网站上找相关代码 -->
<body>
 
<div class="container">
  <div class="row">
    <div class="col-md-6 col-md-offset-3">
 
      <div class="panel panel-primary">
        <div class="panel-heading">添加书籍</div>
        <div class="panel-body">
          <form class="form-horizontal" action="/add_book/" method="post">
            <div class="form-group">
              <label for="book_title" class="col-sm-2 control-label">书名</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="book_title" name="book_title"
                    placeholder="书名">
              </div>
            </div>
            <div class="form-group">
              <label for="inputPassword3" class="col-sm-2 control-label">出版社</label>
              <div class="col-sm-10">
                <select class="form-control" name="publisher">
                  {% for publisher in publisher_list %}
                    <option value="{{ publisher.id }}">{{ publisher.name }}</option>
                  {% endfor %}
                </select>
              </div>
            </div>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-success">提交</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
</html>

修改过程:

先写一个 container

Django使用 Bootstrap 样式修改书籍列表过程解析

找一个面板,在 Bootstrap 的组件中可找到

Django使用 Bootstrap 样式修改书籍列表过程解析

复制代码,并进行修改

Django使用 Bootstrap 样式修改书籍列表过程解析

现在需要一个 form 表单,在 Bootstrap 的全局 CSS 样式中找

Django使用 Bootstrap 样式修改书籍列表过程解析

复制下面的代码,替换面板代码中的 Panel content,并进行修改

先修改 email 处

<div class="form-group">
  <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
  <div class="col-sm-10">
    <input type="email" class="form-control" id="inputEmail3" placeholder="Email">
  </div>
</div>

修改为:

<div class="form-group">
  <label for="book_title" class="col-sm-2 control-label">书名</label>
  <div class="col-sm-10">
    <input type="text" class="form-control" id="book_title" name="book_title" placeholder="书名">
  </div>
</div>

再来修改 password 处,这里需要用到下拉列表,还是去 Bootstrap 上找

在 “菜单” -> "被支持的控件" 处

Django使用 Bootstrap 样式修改书籍列表过程解析

复制代码,并进行修改

<div class="form-group">
  <label for="inputPassword3" class="col-sm-2 control-label">Password</label>
  <div class="col-sm-10">
    <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
  </div>
</div>

修改为:

<div class="form-group">
  <label for="inputPassword3" class="col-sm-2 control-label">出版社</label>
  <!-- 下拉列表 -->
  <div class="col-sm-10">
    <select class="form-control" name="publisher">
      {% for publisher in publisher_list %}
        <option value="{{ publisher.id }}">{{ publisher.name }}</option>
      {% endfor %}
    </select>
  </div>
</div>

接着修改剩下的部分

Django使用 Bootstrap 样式修改书籍列表过程解析

最后在 form 表单处添加 action 和 method

Django使用 Bootstrap 样式修改书籍列表过程解析

运行效果:

Django使用 Bootstrap 样式修改书籍列表过程解析

编辑书籍:

最后修改 edit_book.html

<!DOCTYPE html>
<!-- saved from url=(0042)https://v3.bootcss.com/examples/dashboard/ -->
<html lang="zh-CN">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="https://v3.bootcss.com/favicon.ico" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 
  <title>编辑书籍</title>
  <!-- Bootstrap core CSS -->
  <link href="/static/bootstrap/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">
  <!-- Custom styles for this template -->
  <link href="/static/dashboard.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">
  <link rel="stylesheet" href="/static/fontawesome/css/font-awesome.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
</head>
<body>
 
<div class="container">
  <div class="row">
    <div class="col-md-6 col-md-offset-3">
 
      <div class="panel panel-primary">
        <div class="panel-heading">编辑书籍</div>
        <div class="panel-body">
          <form class="form-horizontal" action="/edit_book/" method="post">
            <input type="text" style="display: none" name="id" value="{{ book_obj.id }}">
            <div class="form-group">
              <label for="book_title" class="col-sm-2 control-label">书名</label>
              <div class="col-sm-10">
                <input type="text" class="form-control" id="book_title" name="book_title"
                    placeholder="书名" value="{{ book_obj.title }}">
              </div>
            </div>
            <div class="form-group">
              <label for="inputPassword3" class="col-sm-2 control-label">出版社</label>
              <div class="col-sm-10">
                <select class="form-control" name="publisher">
                  {% for publisher in publisher_list %}
                    {# 通过 if 条件判断来选择默认出版社 #}
                    {% if book_obj.publisher_id == publisher.id %}
                      {# 默认选择当前书籍关联的出版社 #}
                      <option selected value="{{ publisher.id }}">{{ publisher.name }}</option>
                    {% else %}
                      {# 其他的出版社不选中 #}
                      <option value="{{ publisher.id }}">{{ publisher.name }}</option>
                    {% endif %}
                  {% endfor %}
                </select>
              </div>
            </div>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-success">提交</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div> 
</body>
</html>

修改过程:

首先把 add_book.html 复制过去,然后修改相关标题,把 “添加书籍” 改为 “编辑书籍”

然后在 form 表单下一行添加一个有书籍 id 的 input 标签

Django使用 Bootstrap 样式修改书籍列表过程解析

然后在书名的那个 input 处添加一个 value

Django使用 Bootstrap 样式修改书籍列表过程解析

然后将下拉列表的出版社选择改为原 edit_book.html 的

Django使用 Bootstrap 样式修改书籍列表过程解析

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
详解Python中break语句的用法
May 14 Python
Python IDE PyCharm的基本快捷键和配置简介
Nov 04 Python
Python 处理数据的实例详解
Aug 10 Python
Python利用multiprocessing实现最简单的分布式作业调度系统实例
Nov 14 Python
Django权限机制实现代码详解
Feb 05 Python
Python实现批量修改图片格式和大小的方法【opencv库与PIL库】
Dec 03 Python
查看python安装路径及pip安装的包列表及路径
Apr 03 Python
Django model update的多种用法介绍
Mar 28 Python
Pytorch to(device)用法
Jan 08 Python
python实现一个猜拳游戏
Apr 05 Python
python基于opencv 实现图像时钟
Jan 04 Python
能让Python提速超40倍的神器Cython详解
Jun 24 Python
python实现网站用户名密码自动登录功能
Aug 09 #Python
Django 多表关联 存储 使用方法详解 ManyToManyField save
Aug 09 #Python
ORM Django 终端打印 SQL 语句实现解析
Aug 09 #Python
python实现读取excel文件中所有sheet操作示例
Aug 09 #Python
django ManyToManyField多对多关系的实例详解
Aug 09 #Python
python虚拟环境的安装和配置(virtualenv,virtualenvwrapper)
Aug 09 #Python
python实现比对美团接口返回数据和本地mongo数据是否一致示例
Aug 09 #Python
You might like
file_get_contents获取不到网页内容的解决方法
2013/03/07 PHP
php自定义类fsocket模拟post或get请求的方法
2015/07/31 PHP
PHP随机获取未被微信屏蔽的域名(微信域名检测)
2017/03/19 PHP
php实现和c#一致的DES加密解密实例
2017/07/24 PHP
php7安装mongoDB扩展的方法分析
2017/08/02 PHP
PHP实现微信小程序用户授权的工具类示例
2019/03/05 PHP
基于JQuery的数字改变的动画效果--可用来做计数器
2010/08/11 Javascript
JavaScript继承方式实例
2010/10/29 Javascript
javascript 运算数的求值顺序
2011/08/23 Javascript
Javascript 面向对象(二)封装代码
2012/05/23 Javascript
js获取字符串最后一位方法汇总
2014/11/13 Javascript
js实现网页右上角滑出会自动消失大幅广告的方法
2015/02/27 Javascript
JavaScript实现DIV层拖动及动态增加新层的方法
2015/05/12 Javascript
浅谈Vue的基本应用
2016/12/27 Javascript
vuejs通过filterBy、orderBy实现搜索筛选、降序排序数据
2020/10/26 Javascript
js事件冒泡与事件捕获详解
2017/02/20 Javascript
js实现时间轴自动排列效果
2017/03/09 Javascript
什么时候不能在 Node.js 中使用 Lock Files
2019/06/24 Javascript
让你30分钟快速掌握vue3教程
2020/10/26 Javascript
[01:55]2014DOTA2国际邀请赛快报:国土生病 紧急去医院治疗
2014/07/10 DOTA
Django与JS交互的示例代码
2017/08/23 Python
利用python实现简单的邮件发送客户端示例
2017/12/23 Python
Python模拟简单电梯调度算法示例
2018/08/20 Python
python中for循环输出列表索引与对应的值方法
2018/11/07 Python
Python检查和同步本地时间(北京时间)的实现方法
2018/12/03 Python
python 进程 进程池 进程间通信实现解析
2019/08/23 Python
python 利用已有Ner模型进行数据清洗合并代码
2019/12/24 Python
Windows上安装tensorflow  详细教程(图文详解)
2020/02/04 Python
Python AutoCAD 系统设置的实现方法
2020/04/01 Python
Python面试题:Python里面如何生成随机数
2015/03/12 面试题
三年级上册科学教学计划
2015/01/21 职场文书
保险公司客户经理岗位职责
2015/04/09 职场文书
大客户经理岗位职责
2015/04/09 职场文书
2016领导干部廉洁自律心得体会
2016/01/13 职场文书
营销策划分析:怎么策划才能更好销量产品?
2019/09/04 职场文书
springboot临时文件存储目录配置方式
2021/07/01 Java/Android