Flask高级编程(一)
一、路由注册两种方式
第一种:在视图函数上使用装饰器来注册路由
from flask import Flask
app = Flask(__name__)
@app.route("/hello") # 第一种注册方法
def hello():
return "hello python!!!"第二种:使用add_url_rule(‘访问路由‘,view_func=视图函数)
def hello_two():
print("换一种注册路由的方式")
return ‘hello, nzh‘
app.add_url_rule(‘/hello_two‘, view_func=hello_two)