bootstrap flask登錄頁(yè)面編寫實(shí)例
本文章來(lái)為各位介紹一個(gè)python的例子,這個(gè)就是bootstrap+flask寫登錄頁(yè)面的例子,希望文章能夠?qū)Ω魑挥兴鶐椭?br />
Flask是一個(gè)使用 Python 編寫的輕量級(jí) Web 應(yīng)用框架。其 WSGI 工具箱采用 Werkzeug ,模板引擎則使用 Jinja2 。在一般應(yīng)用或個(gè)人開(kāi)發(fā)中,可以很容易的寫出應(yīng)用。本篇就結(jié)合bootstrap,寫一個(gè)簡(jiǎn)單的login界面。
一、效果圖
無(wú)圖無(wú)真像,先上效果圖:
flask-bootstrap
flask-login
二、目錄結(jié)構(gòu)
該代碼寫時(shí)采用動(dòng)靜分離的方法進(jìn)行編寫,目錄樹如下:
[root@jb51 login]# tree
.
├── run.py
├── static
│ └── css
│ ├── bootstrap.min.css
│ └── style.css
└── templates
├── index.html
└── login.html
三、入口run文件
動(dòng)態(tài)代碼只有一個(gè)run.py文件,代碼如下:
from flask import * app = Flask(__name__,static_url_path='/static') @app.route("/login",methods=['POST','GET']) def login(): error = None if request.method == 'POST': if request.form['username'] != 'admin' or request.form['password'] != 'admin123': error= "sorry" else: return redirect(url_for('index')) return render_template('login.html',error=error) @app.route("/index") def index(): return render_template('index.html') if __name__ == "__main__": app.run( host="0.0.0.0", port=80, debug=True)
實(shí)際應(yīng)用中,根據(jù)需要,可以關(guān)閉debug模試。
四、靜態(tài)模塊
templates下有兩個(gè)模塊文件分別是login.html和index.html
login.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1.0" /> <title>Bootstrap響應(yīng)式登錄界面模板</title> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bootstrap.min.css') }}"> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}"> </head> <body> <div class="box"> <div class="login-box"> <div class="login-title text-center"> <h1><small>登錄</small></h1> </div> <div class="login-content "> <div class="form"> <form action="#" method="post"> <div class="form-group"> <div class="col-xs-12 "> <div class="input-group"> <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span> <input type="text" id="username" name="username" class="form-control" placeholder="用戶名"> </div> </div> </div> <div class="form-group"> <div class="col-xs-12 "> <div class="input-group"> <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span> <input type="text" id="password" name="password" class="form-control" placeholder="密碼"> </div> </div> </div> <div class="form-group form-actions"> <div class="col-xs-4 col-xs-offset-4 "> <button type="submit" class="btn btn-sm btn-info"><span class="glyphicon glyphicon-off"></span> 登錄</button> </div> </div> <div class="form-group"> <div class="col-xs-6 link"> <p class="text-center remove-margin"><small>忘記密碼?</small> <a href="javascript:void(0)" ><small>找回</small></a> </p> </div> <div class="col-xs-6 link"> <p class="text-center remove-margin"><small>還沒(méi)注冊(cè)?</small> <a href="javascript:void(0)" ><small>注冊(cè)</small></a> </p> </div> </div> </form> </div> </div> </div> </div> <div style="text-align:center;"><p>來(lái)源:<a href="http://www.dbjr.com.cn/" target="_blank">運(yùn)維之路</a></p></div> </body> </html>
index.html
index.html 模板中內(nèi)容如下:
<h1>welcome to www.dbjr.com.cn/ <h1>
如果大家還想深入學(xué)習(xí),可以點(diǎn)擊這里進(jìn)行學(xué)習(xí),再為大家附兩個(gè)精彩的專題:Bootstrap學(xué)習(xí)教程 Bootstrap實(shí)戰(zhàn)教程
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Bootstrap實(shí)現(xiàn)登錄校驗(yàn)表單(帶驗(yàn)證碼)
- 使用BootStrap實(shí)現(xiàn)用戶登錄界面UI
- jfinal與bootstrap的登錄跳轉(zhuǎn)實(shí)戰(zhàn)演習(xí)
- php bootstrap實(shí)現(xiàn)簡(jiǎn)單登錄
- 分享Bootstrap簡(jiǎn)單表格、表單、登錄頁(yè)面
- Bootstrap彈出帶合法性檢查的登錄框?qū)嵗a【推薦】
- PHP實(shí)現(xiàn)登錄注冊(cè)之BootStrap表單功能
- 基于Bootstrap實(shí)現(xiàn)下拉菜單項(xiàng)和表單導(dǎo)航條(兩個(gè)菜單項(xiàng),一個(gè)下拉菜單和登錄表單導(dǎo)航條)
- Bootstrap中文本框的寬度變窄并且加入一副驗(yàn)證碼圖片的實(shí)現(xiàn)方法
- Bootstrap實(shí)現(xiàn)前端登錄頁(yè)面帶驗(yàn)證碼功能完整示例
相關(guān)文章
js鼠標(biāo)按鍵事件和鍵盤按鍵事件用法實(shí)例匯總
這篇文章主要介紹了js鼠標(biāo)按鍵事件和鍵盤按鍵事件用法,結(jié)合實(shí)例形式總結(jié)分析了JavaScript針對(duì)鼠標(biāo)與鍵盤事件的常用操作技巧,需要的朋友可以參考下2016-10-10關(guān)于layui 彈出層一閃而過(guò)就消失的解決方法
今天小編就為大家分享一篇關(guān)于layui 彈出層一閃而過(guò)就消失的解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09javascript 網(wǎng)站常用的iframe分割
就是一個(gè)頁(yè)面使用兩個(gè)iframe來(lái)調(diào)用內(nèi)容,實(shí)現(xiàn)頁(yè)面導(dǎo)航,更容易控制,可控制性好2008-06-06js傳遞數(shù)組參數(shù)到后臺(tái)controller的方法
下面小編就為大家分享一篇js傳遞數(shù)組參數(shù)到后臺(tái)controller的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-03-03基于p5.js 2D圖像接口的擴(kuò)展(交互實(shí)現(xiàn))
這篇文章主要為大家詳細(xì)介紹了基于p5.js 2D圖像接口的擴(kuò)展,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11DIV層之拖動(dòng)、關(guān)閉、打開(kāi)效果代碼
非常不錯(cuò)的效果,適合在當(dāng)前頁(yè)打開(kāi)測(cè)試窗口,圖片等2008-09-09