侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

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

框架(架构)  /  管理员 发布于 7年前   148

展示书籍列表:

首先修改原先的 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="https:static/bootstrap/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">  <!-- Custom styles for this template -->  <link href="https:static/dashboard.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">  <link rel="stylesheet" href="https: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="https:publisher_list/" rel="external nofollow" >出版社列表页</a></li>        <li class="active"><a href="https:book_list/" rel="external nofollow" >书籍列表</a></li>        <li><a href="https: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="https: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="https:del_book/?id={{ book.id }}" rel="external nofollow" >删除</a>      <a class="btn btn-info" href="https: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="https:static/jquery-3.3.1.js"></script><script src="https:static/bootstrap/js/bootstrap.min.js"></script> </body></html>

修改过程:

运行效果:

添加书籍:

再来修改 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="https:static/bootstrap/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">  <!-- Custom styles for this template -->  <link href="https:static/dashboard.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">  <link rel="stylesheet" href="https: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

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

复制代码,并进行修改

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

复制下面的代码,替换面板代码中的 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 上找

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

复制代码,并进行修改

<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>

接着修改剩下的部分

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

运行效果:

编辑书籍:

最后修改 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="https:static/bootstrap/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">  <!-- Custom styles for this template -->  <link href="https:static/dashboard.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">  <link rel="stylesheet" href="https: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 标签

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

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

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


  • 上一条:
    在Django admin中编辑ManyToManyField的实现方法
    下一条:
    Django 多表关联 存储 使用方法详解 ManyToManyField save
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • Filament v3.1版本发布(0个评论)
    • docker + gitea搭建一个git服务器流程步骤(0个评论)
    • websocket的三种架构方式使用优缺点浅析(0个评论)
    • ubuntu20.4系统中宿主机安装nginx服务,docker容器中安装php8.2实现运行laravel10框架网站(0个评论)
    • phpstudy_pro(小皮面板)中安装最新php8.2.9版本流程步骤(0个评论)
    • 近期文章
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • Laravel 11.15版本发布 - Eloquent Builder中添加的泛型(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2018-05
    • 2020-02
    • 2020-03
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-11
    • 2021-03
    • 2021-09
    • 2021-10
    • 2021-11
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-08
    • 2023-08
    • 2023-10
    • 2023-12
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客