Django
Django有个bootstrap3插件,可以简化对bootstrap3的使用,github上有其的项目:https://github/dyve/django-bootstrap3
打开帮助可以看其具体使用方法:
安装插件 pip install django-bootstrap3在项目settings.py上的INSTALLED_APPS中加入 'bootstrap3,'在模版中,加载bootstrap3库,用 bootstrap_*的标签,如下:<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> {% load bootstrap3 %} {% bootstrap_css %} {% bootstrap_javascript %} {% bootstrap_messages %} <!-- Custom styles for this template --> <!--link href="../signin.css" rel="stylesheet"--> <link href="/examples/signin/signin.css" rel="stylesheet"> </head> <body> <div class="container"> <form class="form-signin" action="/login_action/" method="post"> <h2 class="form-signin-heading">用户登录</h2> <label for="inputUsername" class="sr-only">username</label> <input type="text" id="inputUsername" name="username" class="form-control" placeholder="username" required autofocus> <label for="inputPassword" class="sr-only">password</label> <input type="password" id="inputPassword" name="password" class="form-control" placeholder="password" required> <button class="btn btn-lg btn-primary btn-block" type="submit" id="btn">登录</button> {{wronglyInput}}<br> {% csrf_token %} </form> </div> <!-- /container --> </body></html>4.更多细节参考官方的标签说明:.html
5.实例,用Django-bootstrap3改造 "Python web模版Django-22 Bootstrap美化HTML之用BootCDN"章中开发的index.html.
原始的html文件:
<!DOCTYPE html><html lang="en"> <head> <meta 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="../../favicon.ico"> <title>Django Page</title> <!-- Bootstrap core CSS --> <link href="/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> <link href="/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> <!-- Custom styles for this template --> <link href="/examples/signin/signin.css" rel="stylesheet"> <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> <script src="/assets/js/ie-emulation-modes-warning.js"></script> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]> <script src="/html5shiv/3.7.3/html5shiv.min.js"></script> <script src="/respond.js/1.4.2/respond.min.js"></script> <![endif]--> </head> <body> <div class="container"> <form class="form-signin" action="/login_action/" method="post"> <h2 class="form-signin-heading">发布会管理</h2> <label for="inputUsername" class="sr-only">username</label> <input type="text" id="inputUsername" name="username" class="form-control" placeholder="username" required autofocus> <label for="inputPassword" class="sr-only">password</label> <input type="password" id="inputPassword" name="password" class="form-control" placeholder="password" required> <button class="btn btn-lg btn-primary btn-block" type="submit" id="btn">登录</button> {{wronglyInput}}<br> {% csrf_token %} </form> </div> <!-- /container --> <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> <script src="/assets/js/ie10-viewport-bug-workaround.js"></script> </body></html>改造:将上面绿色部分都删掉,然后用Django-bootstrap3改造,把bootstrap中相关的css, javascript等标签加入,如下
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> <script type="text/javascript" src="/static/js/jquery-1.12.4.min.js"></script> {% load bootstrap3 %} {% bootstrap_css %} {% bootstrap_javascript %} {% bootstrap_messages %} <!-- Custom styles for this template --> <!--link href="../signin.css" rel="stylesheet"--> <link href="/examples/signin/signin.css" rel="stylesheet"> </head> <body> <div class="container"> <form class="form-signin" action="/login_action/" method="post"> <h2 class="form-signin-heading">用户登录</h2> <label for="inputUsername" class="sr-only">username</label> <input type="text" id="inputUsername" name="username" class="form-control" placeholder="username" required autofocus> <label for="inputPassword" class="sr-only">password</label> <input type="password" id="inputPassword" name="password" class="form-control" placeholder="password" required> <button class="btn btn-lg btn-primary btn-block" type="submit" id="btn">登录</button> {{wronglyInput}}<br> {% csrf_token %} </form> </div> <!-- /container --> </body></html>
Django-bootstrap3插件搭建Django+Bootstrap网站