【问题标题】:Replace flask_peewee.db with plain peewee module?用普通的peewee模块替换flask_peewee.db?
【发布时间】:2016-03-23 07:55:15
【问题描述】:

我有一个烧瓶应用程序,它在其应用程序模块中使用了 flask_peewee.db:

from flask_peewee.db import Database

是否可以用普通 peewee 模块替换 flask_peewee 数据库模块? flask_peewee 的作者说它处于维护模式,虽然不完全是日落,但我不愿意使用它开始一个新项目。不幸的是,我喜欢烧瓶/peewee 组合,并且似乎 flask_peewee 可能是将两者结合在一起而不会心痛的唯一方法。想法?

【问题讨论】:

    标签: python flask peewee flask-peewee


    【解决方案1】:

    你可以试试playhouse.flask_utils中的FlaskDB对象:

    http://docs.peewee-orm.com/en/latest/peewee/playhouse.html#database-wrapper

    虽然不是 100% 相同,但我认为这可能对您有用。

    【讨论】:

    • 谢谢,查尔斯。我用 CPython 2.7、pypy 2.7 和 CPython 3.5 尝试了你的建议。 2.7 变体在模型类上产生 stackoverflow.com/questions/11276037/…。 3.5 变体在 UserRoles m2m 链接表上产生此错误:stackoverflow.com/questions/2464568/… 我尝试了各种解决这些错误的建议,但都没有奏效。
    • 我想通了。我将 FlaskDB.Model 作为模型的基类而不是 db 实例模型传递。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-12
    • 2023-03-07
    • 2019-03-09
    • 1970-01-01
    • 2016-12-21
    • 2016-10-31
    相关资源
    最近更新 更多