Request对象
from flask import Flask,request
app = Flask(__name__)
@app.route('/hello')
def hello():
#存在xss安全风险,http://xxxx.com?name=333
name = request.args.get('name','Flask')
return '<h1>Hello %s</h1>' % name
@app.route('/',methods={'GET','POST'})
def hi():
return '<h1>hi,World!</h1>'
@app.route('/goback/<int:year>')
def go_back(year):
return '<p>Welcomet ot %d</p>' % (2018-year)
@app.route('/colors/<any(blue,white,red):color>')
def three_colors(color):
return '<p>Love is patient and kind.</p>'
请求钩子
@app.before_request
def do():
something
重定向
from flask import Flask,redirect,url_for
@app.route('/test')
def test():
return redirect('https://www.baidu.com')
#return redirect(url_for('hello')) 不能填成/hello
禁止访问
from flask import Flask,abort
@app.route('/4041')
def not_found():
abort(403)