🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
index.py: ``` from flask import Flask, redirect, url_for, render_template, request from flask_cors import CORS app = Flask(__name__) # r'/*' 是通配符,让本服务器所有的URL 都允许跨域请求 CORS(app, resources=r'/*') @app.route("/") def home(): return render_template("index.html") @app.route("/login", methods=["POST", "GET"]) def login(): if request.method == "POST": user = request.form["nm"] return redirect(url_for("user", usr=user)) else: return render_template("login.html") @app.route("/<usr>") def user(usr): return f"Get data: {usr}" if __name__ == "__main__": app.run(debug=True) ``` templates/index.html: ``` {% block title %}Login Page{% endblock %} {% block content %} <form action="/login" method="post"> <p>Name:</p> <p><input type="text" name="nm" ></p> <p><input type="submit" value="submit" ></p> </form> {% endblock %} ``` 在python控制臺或者cmd上運行python文件