flask用户登录模拟
一、编写表单文件index.html
<form action ="http://localhost:5000/login"method = "post">
<p>用户名</p>
<p><input type="text" name="biaodan"/></p>
<p><input type="submit" value="确定"/></p>
</form>
二、编写程序文件login.py
from flask import Flask, redirect, url_for, request
app = Flask(__name__)<form action ="http://localhost:5000/login"method = "post">
<p>用户名</p>
<p><input type="text" name="biaodan"/></p>
<p><input type="submit" name="确定"/></p>
</form>
'/success/<name>') .route(
def success(name):
return'%s,欢迎光临!'%name
'/login',methods = ['POST','GET']) .route(
def login():
if request.method == 'POST':
user = request.form['biaodan']
return redirect(url_for('success',name = user))
else:
user = request.args.get('biaodan')
return redirect(url_for('success',name = user))
if __name__ == '__main__':
app.run(debug = True)
打开index.html,效果图下图:
输入用户名,点击确定,效果如下图: