阅读时间大概三分钟

本代码是 flask入门篇,适合初学者 ,拿来即可运行。

目录

​功能介绍​

​效果图​

​HTML​

​python ​

​运行(代码目录)​


功能介绍

实现输入固定账号密码跳转到百度首页,持续更新,需要请关注

效果图

python3之flask快速入门教程Demo_html

HTML

HTML文件放在 templates 目录下

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div align="center">
<h2>User Management</h2>
{% if message %} {{message}} {% endif %}
<form method="POST">

<input type="text" name="username" placeholder="username">
<br>
<input type="password" name="password" placeholder="password">
<br>
<input type="submit" value="Submit">
<input type="reset" value="reset">
</form>
</div>

</body>
</html>

python 

from flask import Flask,request,render_template,redirect

app = Flask(__name__)
#绑定访问地址127.0.0.1:5000/user
@app.route("/user",methods=['GET','POST'])
def login():
if request.method =='POST':
username = request.form['username']
password = request.form['password']
if username =="user" and password=="password":
return redirect("http://www.baidu.com")
else:
message = "Failed Login"
return render_template('login.html',message=message)
return render_template('login.html')

if __name__ == '__main__':
app.run(debug=True)

运行(代码目录)

 以下为效果图

python3之flask快速入门教程Demo_html_02

 python3之flask快速入门教程Demo_html