我使用Flask limiter扩展来限制特定路由的页面请求数(除非他们以管理员身份登录)。我正在使用Flask Stormpath扩展来管理我的用户身份验证。在
由于某些原因,我的现有函数返回以下错误:
Traceback (most recent call last):
File "index.py", line 772, in <module>
@limiter.limit("20/hour", exempt_when=admin_conditions())
File "index.py", line 114, in admin_conditions
if current_app.user.is_authenticated():
File "c:\Python27\lib\site-packages\werkzeug\local.py", line 338, in __getattr
__
return getattr(self._get_current_object(), name)
File "c:\Python27\lib\site-packages\werkzeug\local.py", line 297, in _get_curr
ent_object
return self.__local()
File "c:\Python27\lib\site-packages\flask\globals.py", line 34, in _find_app
raise RuntimeError('working outside of application context')
RuntimeError: working outside of application context
这是我的代码:
^{2}$我读到了管理条件函数是由烧瓶限制器在request context中调用的,但我不知道如何从那里访问user对象。你知道怎么回事吗?在
您应该将函数传递给decorator,而不是函数的结果。在
请注意缺少
()
,因此没有立即调用函数。目前,函数在定义时执行,在应用程序运行和处理请求之前。在相关问题 更多 >
编程相关推荐