'''
pip install flack
'''
from flask import Flask
app = Flask('__name__')
# 静态路由
@app.route('/')
def index():
return 'root
'
@app.route('/greet')
def greet():
return 'Hello everyone
'
@app.route('/greet/bill')
def greetBill():
return '你好 Bill
'
# 动态路由
@app.route('/greet/')
def greetName(name):
return 'Hello {}
'.format(name)
'''
如果静态路由和动态路由有冲突,优先使用静态路由
'''
@app.route('/greet///')
def args1(a1, a2, a3):
return '{},{},{}
'.format(a1, a2, a3)
@app.route('/greet/--')
def args2(a1, a2, a3):
return '{}*{}*{}
'.format(a1, a2, a3)
if __name__ == '__main__':
app.run()
* Serving Flask app "__name__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [31/Mar/2020 15:57:45] "GET /greet/bill/1/2 HTTP/1.1" 200 -
127.0.0.1 - - [31/Mar/2020 15:57:54] "GET /greet/1-2-3 HTTP/1.1" 200 -
96 - 用Flask实现转发与重定向