功能介绍
实现输入固定账号密码跳转到百度首页,持续更新,需要请关注
效果图
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)
运行(代码目录)
以下为效果图