#方式一 @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字段中