<form name="input" action="/register" method="post"> Username: <input type="text" name="user"> <input type="submit" value="Submit"> </form>
from flask import Flask,render_template,request app = Flask(__name__) @app.route(‘/‘) def index(): return render_template(‘index.html‘) @app.route(‘/register‘, methods = [‘GET‘, ‘POST‘]) def register(): print(request.method) print(request.form[‘user‘]) return ‘welcome‘ if __name__ == ‘__main__‘: app.run()
接下来是读get的数据
from flask import Flask,render_template,request app = Flask(__name__) @app.route(‘/‘) def index(): return render_template(‘index.html‘) @app.route(‘/register‘, methods = [‘GET‘, ‘POST‘]) def register(): print(request.method) print(request.args.get(‘user‘)) return ‘welcome‘ if __name__ == ‘__main__‘: app.run()