跟着老师bilibili里的《2022版-零基础玩转Python Flask框架-学完可就业》课程学习,学到  访问限制login_required。出现如下错误,要怎么解决。
错误提示:

RuntimeError: Working outside of application context.

This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.

代码:
decorators.py文件

from flask import g, redirect, url_for
from functools import wraps

def login_required(func):
# wraps这个装饰器一定不要忘记写,
@wraps(func)
def wrapper(*args, **kwargs):
if hasattr(g,"user"):
return func(*args, **kwargs)
else:
return redirect(url_for("user.login"))

return wrapper()