bootstrap flask登錄頁(yè)面編寫(xiě)實(shí)例
本文章來(lái)為各位介紹一個(gè)python的例子,這個(gè)就是bootstrap+flask寫(xiě)登錄頁(yè)面的例子,希望文章能夠?qū)Ω魑挥兴鶐椭?br />
Flask是一個(gè)使用 Python 編寫(xiě)的輕量級(jí) Web 應(yīng)用框架。其 WSGI 工具箱采用 Werkzeug ,模板引擎則使用 Jinja2 。在一般應(yīng)用或個(gè)人開(kāi)發(fā)中,可以很容易的寫(xiě)出應(yīng)用。本篇就結(jié)合bootstrap,寫(xiě)一個(gè)簡(jiǎn)單的login界面。
一、效果圖
無(wú)圖無(wú)真像,先上效果圖:

flask-bootstrap

flask-login
二、目錄結(jié)構(gòu)
該代碼寫(xiě)時(shí)采用動(dòng)靜分離的方法進(jìn)行編寫(xiě),目錄樹(shù)如下:
[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.dhdzp.com/" target="_blank">運(yùn)維之路</a></p></div>
</body>
</html>
index.html
index.html 模板中內(nèi)容如下:
<h1>welcome to www.dhdzp.com/ <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)文章
JavaScript Promise與async/await作用詳細(xì)講解
Promise是異步編程的一種解決方案:從語(yǔ)法上講,promise是一個(gè)對(duì)象,從它可以獲取異步操作的消息;從本意上講,它是承諾,承諾它過(guò)一段時(shí)間會(huì)給你一個(gè)結(jié)果2023-01-01
如何將JavaScript將數(shù)組轉(zhuǎn)為樹(shù)形結(jié)構(gòu)
我們經(jīng)常會(huì)碰到樹(shù)形數(shù)據(jù)結(jié)構(gòu),比方組織層級(jí)、省市縣或者者動(dòng)植物分類等等數(shù)據(jù),那么如何將JavaScript將數(shù)組轉(zhuǎn)為樹(shù)形結(jié)構(gòu),本文就詳細(xì)的來(lái)了解一下2021-06-06
javascript之典型高階函數(shù)應(yīng)用介紹二
在前一篇文章javascript之典型高階函數(shù)中主要實(shí)現(xiàn)了幾個(gè)典型的functional函數(shù),文章最后也提出了疑問(wèn),為啥那樣的實(shí)現(xiàn)與F#之類的函數(shù)式語(yǔ)言“不太一樣”呢?今天來(lái)試試更“函數(shù)式”的實(shí)現(xiàn)2013-01-01
javascript Onunload與Onbeforeunload使用小結(jié)
Onunload,onbeforeunload都是在刷新或關(guān)閉時(shí)調(diào)用,可以在<script>腳本中通過(guò)window.onunload來(lái)指定或者在<body>里指定。區(qū)別在于onbeforeunload在onunload之前執(zhí)行,它還可以阻止onunload的執(zhí)行。2009-12-12
js 如何實(shí)現(xiàn)對(duì)數(shù)據(jù)庫(kù)的增刪改查
JavaScript操作數(shù)據(jù)庫(kù)JS操作Access數(shù)據(jù)庫(kù),跟其他語(yǔ)言操作差不多,總結(jié)了一下習(xí)慣代碼,需要的朋友可以參考下2012-11-11
javascript dragable的Move對(duì)象
一個(gè)dragable的Move對(duì)象,大家可以運(yùn)行下,測(cè)試看下效果。2009-08-08
JavaScript?中什么時(shí)候使用?Map?更好
這篇文章主要介紹了JavaScript中什么時(shí)候使用Map更好,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08
JS獲取字符串實(shí)際長(zhǎng)度(包含漢字)的簡(jiǎn)單方法
下面小編就為大家?guī)?lái)一篇JS獲取字符串實(shí)際長(zhǎng)度(包含漢字)的簡(jiǎn)單方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-08-08
webpack5新特性Asset?Modules資源模塊詳解
這篇文章主要為大家介紹了webpack5新特性Asset?Modules資源模塊詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03

