s3hengwu111
V2EX  ›  问与答

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

  •  
  •   s3hengwu111 · Mar 22, 2019 · 1806 views
    This topic created in 2615 days ago, the information mentioned may be changed or developed.

    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 操作的时候报错?有大神讲解一下吗?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5079 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 09:19 · PVG 17:19 · LAX 02:19 · JFK 05:19
    ♥ Do have faith in what you're doing.