Django使用 Bootstrap 樣式修改書籍列表過程解析
展示書籍列表:
首先修改原先的 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個(gè)meta標(biāo)簽*必須*放在最前面,任何其他內(nèi)容都*必須*跟隨其后! --> <meta name="description" content=""> <meta name="author" content=""> <link rel="icon" 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" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >圖書管理系統(tǒng)</a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav navbar-right"> <li><a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Dashboard</a></li> <li><a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Settings</a></li> <li><a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Profile</a></li> <li><a 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 表示當(dāng)前頁面,會(huì)加亮 --> <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 --> <!-- 跳轉(zhuǎn)到另一頁面,添加新的書籍 --> <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>
修改過程:
運(yùn)行效果:
添加書籍:
再來修改 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個(gè)meta標(biāo)簽*必須*放在最前面,任何其他內(nèi)容都*必須*跟隨其后! --> <meta name="description" content=""> <meta name="author" content=""> <link rel="icon" 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 網(wǎng)站上找相關(guān)代碼 --> <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>
修改過程:
先寫一個(gè) container
找一個(gè)面板,在 Bootstrap 的組件中可找到
復(fù)制代碼,并進(jìn)行修改
現(xiàn)在需要一個(gè) form 表單,在 Bootstrap 的全局 CSS 樣式中找
復(fù)制下面的代碼,替換面板代碼中的 Panel content,并進(jìn)行修改
先修改 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 上找
在 “菜單” -> "被支持的控件" 處
復(fù)制代碼,并進(jìn)行修改
<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
運(yùn)行效果:
編輯書籍:
最后修改 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個(gè)meta標(biāo)簽*必須*放在最前面,任何其他內(nèi)容都*必須*跟隨其后! --> <meta name="description" content=""> <meta name="author" content=""> <link rel="icon" 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 條件判斷來選擇默認(rèn)出版社 #} {% if book_obj.publisher_id == publisher.id %} {# 默認(rèn)選擇當(dāng)前書籍關(guān)聯(lián)的出版社 #} <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 復(fù)制過去,然后修改相關(guān)標(biāo)題,把 “添加書籍” 改為 “編輯書籍”
然后在 form 表單下一行添加一個(gè)有書籍 id 的 input 標(biāo)簽
然后在書名的那個(gè) input 處添加一個(gè) value
然后將下拉列表的出版社選擇改為原 edit_book.html 的
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
python通過urllib2獲取帶有中文參數(shù)url內(nèi)容的方法
這篇文章主要介紹了python通過urllib2獲取帶有中文參數(shù)url內(nèi)容的方法,涉及Python中文編碼的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03Python中使用HTMLParser解析html實(shí)例
這篇文章主要介紹了Python中使用HTMLParser解析html實(shí)例,本文直接給出使用示例,并總結(jié)出HTMLParser含有的方法分為兩類,一類是需要顯式調(diào)用的,而另一類不需顯示調(diào)用,需要的朋友可以參考下2015-02-02Python的面向?qū)ο缶幊谭绞綄W(xué)習(xí)筆記
Python深度具備面向?qū)ο缶幊陶Z言所應(yīng)有的特性,這里我們以類和方法為主,來整理一下Python的面向?qū)ο缶幊谭绞綄W(xué)習(xí)筆記:2016-07-07Python機(jī)器學(xué)習(xí)logistic回歸代碼解析
這篇文章主要介紹了Python機(jī)器學(xué)習(xí)logistic回歸代碼解析,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01利用python循環(huán)創(chuàng)建多個(gè)文件的方法
今天小編就為大家分享一篇利用python循環(huán)創(chuàng)建多個(gè)文件的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-10-105種Python統(tǒng)計(jì)次數(shù)方法技巧
這篇文章主要給大家分享的是5種Python統(tǒng)計(jì)次數(shù)方法技巧,文章主要包括字典 dict 統(tǒng)計(jì)、collections.defaultdict 統(tǒng)計(jì)、List count方法、集合(set)和列表(list)統(tǒng)計(jì)、collections.Counter方法,感興趣的小伙伴一起進(jìn)入下面文章內(nèi)容吧2021-11-11python生成多個(gè)只含0,1元素的隨機(jī)數(shù)組或列表的實(shí)例
今天小編就為大家分享一篇python生成多個(gè)只含0,1元素的隨機(jī)數(shù)組或列表的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-11-11使用Python webdriver圖書館搶座自動(dòng)預(yù)約的正確方法
這篇文章主要介紹了使用Python webdriver圖書館搶座自動(dòng)預(yù)約的正確方法,本文通過圖文實(shí)例相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03tkinter高級(jí)布局之PanedWindow和notebook詳解
本文主要介紹了tkinter中的兩種布局控件,分別是可以動(dòng)態(tài)劃分子控件的PanedWindow,和提供了選項(xiàng)卡工具的notebook,感興趣的小伙伴可以學(xué)習(xí)一下2023-08-08Python zip函數(shù)打包元素實(shí)例解析
這篇文章主要介紹了Python zip函數(shù)打包元素實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12