首页 > flask怎么给一个类统一的url前缀

flask怎么给一个类统一的url前缀

@app.route('/Admin')
class AdminController():
    @app.route('/GetModel')
    def GetModel():
         return json.dumps({'hello': 'GetModel'})
    @app.route('/GetList')
    def GetList():
        return json.dumps({'hello': 'GetList'})

例如假设可以这样写。
我想用 /admin/getmodeladmin/getlist能分别访问到这2个方法,
但是可惜,貌似不支持在class上面定义一个统一的路由端点?


可以看下blueprint


初始化App的时候绑定

DEFAULT_MODULES = (
    (views.home, ""),
    (views.account, "/admin/account"),
)

def configure_modules(app, modules):
    for module, url_prefix in modules:
        app.register_module(module, url_prefix=url_prefix)
【热门文章】
【热门文章】