from flask_classful import route, FlaskView
from flask import current_app as app
class ProductsView(FlaskView):
decorators = [
app.extensions["limiter"].limit("2/minute", methods=['GET']),
]
@route("", methods=["GET"])
def search(self):
pass
在我的create_app()
函数中,我初始化了我的限制器:
from flask_limiter.util import get_remote_address
from flask_limiter import Limiter
limiter = Limiter(key_func=get_remote_address)
limiter.init_app(app)
问题是我进入RuntimeError: Working outside of application context.
了decorators = [
. 我如何单独为我的每个方法使用限制器?并且还解决了这个错误?