1、在蓝图__init__.py中添加装饰器函数, 这里需要注意的是,装饰器需定义在 api初始化之前
""" App蓝图 """ from flask import Blueprint, request from flask_restful import Api # 初始化蓝图 blue = Blueprint('blue', __name__) api = Api(blue) # 装饰器 def test(func): def deco(*args, **kwargs): data = "xxxx" res = func(*args, **kwargs, data=data) return res return deco from .urls import URLS # 配置url for url in URLS: api.add_resource(url['component'], url['path'])
2、urls.py路由
from . import views URLS = [ { "path": "/xx/user_mark_for_app", "message": "测试", "component": views.MarkScore } ]
3、views.py视图
# 用户评分 class MarkScore(BaseApi): def post(self): args = user_mark_for_app_parser.parse_args() data = xx.user_mark_for_app(args=args) self.result.update