本文章来为各位介绍一个python的例子,这个就是bootstrap+flask写登录页面的例子,希望文章能够对各位有所帮助。
Flask是一个使用 Python 编写的轻量级 Web 应用框架。其 WSGI 工具箱采用 Werkzeug ,模板引擎则使用 Jinja2 。在一般应用或个人开发中,可以很容易的写出应用。本篇就结合bootstrap,写一个简单的login界面。
无图无真像,先上效果图:
flask-login
该代码写时采用动静分离的方法进行编写,目录树如下:
[root@jb51 login]# tree
.
├── run.py
├── static
│ └── css
│ ├── bootstrap.min.css
│ └── style.css
└── templates
├── index.html
└── login.html
动态代码只有一个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(
,
port=80,
debug=True)
实际应用中,根据需要,可以关闭debug模试。
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>
<head>
<meta http-equiv="Content-Type" />
<meta />
<title>Bootstrap响应式登录界面模板</title>
<linkstatic',) }}">
<linkstatic',) }}">
</head>
<body>
<div>
<div>
<div>
<h1><small>登录</small></h1>
</div>
<div>
<div>
<form>
<div>
<div>
<div>
<span><span></span></span>
<input>
</div>
</div>
</div>
<div>
<div>
<div>
<span><span></span></span>
<input>
</div>
</div>
</div>
<div>
<div>
<button><span></span> 登录</button>
</div>
</div>
<div>
<div>
<p><small>忘记密码?</small> <a ><small>找回</small></a>
</p>
</div>
<div>
<p><small>还没注册?</small> <a ><small>注册</small></a>
</p>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div ><p>来源:<a>运维之路</a></p></div>
</body>
</html>
index.html
index.html 模板中内容如下:
<h1>welcome to www.jb51.net/ <h1>
如果大家还想深入学习,可以点击这里进行学习,再为大家附两个精彩的专题:Bootstrap学习教程 Bootstrap实战教程
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持51dev开发社区。
以上就是bootstrap flask登录页面编写实例的全部内容,希望对大家的it技术学习有所帮助,希望大家多多支持技术开发者社区。