V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
s3hengwu111
V2EX  ›  问与答

Flask 中,我想在我写的类里面实现, 10 秒后删除一天数据库记录,报错。萌新求解决

  •  
  •   s3hengwu111 · 2019-03-22 11:55:24 +08:00 · 874 次点击
    这是一个创建于 1833 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Timer(10, remove_code, (code, time.time())).start()

    def remove_code(code, v): print("删除 code:" + str(code)) exist_code = Code.query.filter_by(Code.code == code).first() if exist_code: db.session.delete(exist_code) db.session.commit()

    RuntimeError: No application found. Either work inside a view function or push an application context.

    是因为在 timer 里面拿不到 Context 吗,所以在 db 操作的时候报错?有大神讲解一下吗?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3144 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 12:20 · PVG 20:20 · LAX 05:20 · JFK 08:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.