因为有一些配置需要放进数据库里面然后在第一次运行更新到flask config里面的
我使用了以下方法:
@user.before_app_first_request
def before_app_first_request():
current_app.config['CONEL_INFO'] = Conel.query.all()
在第一次访问的时候是正常的,但再次访问会出错:
sqlalchemy.orm.exc.DetachedInstanceError: Instance <Conel at 0x7fbf6f246c50> is not bound to a Session; attribute refresh operation cannot proceed
我觉得是把查询结果绑定在这个 CONEL_INFO 上而已,使用的时候还是会查询上去,有没有方法可以把查询的数据离线存在这个变量
试试把查询结果转换为 list:
list(Conel.query.all())