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

flask-bootstrap

flask-login
二、目錄結(jié)構(gòu)
該代碼寫時采用動靜分離的方法進(jìn)行編寫,目錄樹如下:
[root@jb51 login]# tree
.
├── run.py
├── static
│ └── css
│ ├── bootstrap.min.css
│ └── style.css
└── templates
├── index.html
└── login.html
三、入口run文件
動態(tài)代碼只有一個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)
實際應(yīng)用中,根據(jù)需要,可以關(guān)閉debug模試。
四、靜態(tài)模塊
templates下有兩個模塊文件分別是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>還沒注冊?</small> <a href="javascript:void(0)" ><small>注冊</small></a>
</p>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div style="text-align:center;"><p>來源:<a href="http://m.fzitv.net/" target="_blank">運維之路</a></p></div>
</body>
</html>
index.html
index.html 模板中內(nèi)容如下:
<h1>welcome to m.fzitv.net/ <h1>
如果大家還想深入學(xué)習(xí),可以點擊這里進(jìn)行學(xué)習(xí),再為大家附兩個精彩的專題:Bootstrap學(xué)習(xí)教程 Bootstrap實戰(zhàn)教程
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Bootstrap實現(xiàn)登錄校驗表單(帶驗證碼)
- 使用BootStrap實現(xiàn)用戶登錄界面UI
- jfinal與bootstrap的登錄跳轉(zhuǎn)實戰(zhàn)演習(xí)
- php bootstrap實現(xiàn)簡單登錄
- 分享Bootstrap簡單表格、表單、登錄頁面
- Bootstrap彈出帶合法性檢查的登錄框?qū)嵗a【推薦】
- PHP實現(xiàn)登錄注冊之BootStrap表單功能
- 基于Bootstrap實現(xiàn)下拉菜單項和表單導(dǎo)航條(兩個菜單項,一個下拉菜單和登錄表單導(dǎo)航條)
- Bootstrap中文本框的寬度變窄并且加入一副驗證碼圖片的實現(xiàn)方法
- Bootstrap實現(xiàn)前端登錄頁面帶驗證碼功能完整示例
相關(guān)文章
JavaScript Promise與async/await作用詳細(xì)講解
Promise是異步編程的一種解決方案:從語法上講,promise是一個對象,從它可以獲取異步操作的消息;從本意上講,它是承諾,承諾它過一段時間會給你一個結(jié)果2023-01-01
如何將JavaScript將數(shù)組轉(zhuǎn)為樹形結(jié)構(gòu)
我們經(jīng)常會碰到樹形數(shù)據(jù)結(jié)構(gòu),比方組織層級、省市縣或者者動植物分類等等數(shù)據(jù),那么如何將JavaScript將數(shù)組轉(zhuǎn)為樹形結(jié)構(gòu),本文就詳細(xì)的來了解一下2021-06-06
javascript之典型高階函數(shù)應(yīng)用介紹二
在前一篇文章javascript之典型高階函數(shù)中主要實現(xiàn)了幾個典型的functional函數(shù),文章最后也提出了疑問,為啥那樣的實現(xiàn)與F#之類的函數(shù)式語言“不太一樣”呢?今天來試試更“函數(shù)式”的實現(xiàn)2013-01-01
javascript Onunload與Onbeforeunload使用小結(jié)
Onunload,onbeforeunload都是在刷新或關(guān)閉時調(diào)用,可以在<script>腳本中通過window.onunload來指定或者在<body>里指定。區(qū)別在于onbeforeunload在onunload之前執(zhí)行,它還可以阻止onunload的執(zhí)行。2009-12-12
js 如何實現(xiàn)對數(shù)據(jù)庫的增刪改查
JavaScript操作數(shù)據(jù)庫JS操作Access數(shù)據(jù)庫,跟其他語言操作差不多,總結(jié)了一下習(xí)慣代碼,需要的朋友可以參考下2012-11-11
webpack5新特性Asset?Modules資源模塊詳解
這篇文章主要為大家介紹了webpack5新特性Asset?Modules資源模塊詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03

