绑定路由关系

 

#方式一
@app.route('/index.html',methods=['GET','POST'],endpoint='index')#endpoint是别名

def index():
return 'Index'
复制代码
#方式二

def index():
return "Index"

self.add_url_rule(rule='/index.html', endpoint="index", view_func=index, methods=["GET","POST"]) #endpoint是别名
or
app.add_url_rule(rule='/index.html', endpoint="index", view_func=index, methods=["GET","POST"])
app.view_functions['index'] = index
复制代码

添加路由关系的本质:将url和视图函数封装成一个Rule对象,添加到Flask的url_map字段中

原文地址:https://www.cnblogs.com/wwthuanyu/p/10071451.html