我正在与用户创建一个博客,并向某些页面添加身份验证,要求登录的用户是管理员才能访问某些页面。下面是检查用户是否是管理员的修饰函数:
def admin_only(f):
@wraps(f)
def decorated_function(*args, **kwargs):
try:
user_id = current_user.id
except:
user_id = 0
if user_id == 1:
return f(*args, **kwargs)
else:
return abort(403)
return decorated_function()
我收到以下错误消息:
werkzeug.exceptions.Forbidden: 403 Forbidden: You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.
我已经从烧瓶中导入了中止,所以不能100%确定为什么它说它是禁止的。任何提示,提前谢谢!
尝试从最终返回的修饰函数中删除括号。让它
return decorated_function
而不是return decorated_function()