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

2019-03-22 11:55:24 +08:00
 s3hengwu111

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

898 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/547350

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX