**request模块:**request中封存了客户端的一些信息。可将request当全局变量使用。(P16)
指定视图函数接受的HTTP请求类型:@app.route('path', methods=[type1, type2, ...])
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| from flask import Flask, redirect, url_for, request app = Flask(__name__)
@app.route('/success/<name>') def success(name): return 'welcome {}'.format(name)
@app.route('/login', methods = ['POST', 'GET']) def login(): if request.method == 'POST': user = request.form['nm'] return redirect(url_for('success', name = user)) else: user = request.args.get('nm') return redirect(url_for('success', name = user))
if __name__ == '__main__': app.run(debug = True)
|