本文主要讲的是路由(动态url) 修改index.py中的代码:
from flask import Flask app = Flask(__name__) @app.route('/') def index(): return '<h1>welcome to the system</h1>'
@app.route('/menu') def menu(): return 'this is the menu of the system'
@app.route('/quit') def quit(): return 'you will exit the system' @app.route('/user/<name>') def info(name): return 'hello,%s' % name
if __name__ == '__main__': app.run(debug=True)
上文代码执行效果如下: (1)若访问127.0.0.1:5000 (2)若访问127.0.0.1:5000/menu (3)若访问127.0.0.1:5000/quit (4)若访问127.0.0.1:5000/user/蓝月 |