错误提示:
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()