【发布时间】:2023-03-09 15:44:01
【问题描述】:
我正在尝试使用 Flask、Flask-Login 和 Flask-MongoKit 组装一个基本的登录系统。
这是我的User 课程:
class User(Document):
__collection__ = 'users'
structure = {
'username': basestring,
'password': basestring,
'date_created': datetime
}
required_fields = ['username', 'password']
default_values = {
'date_created': datetime.utcnow
}
当我将 Document 模型连接到数据库 (db.register([User])) 时,对文档 (db.User.one({'username': form.username})) 进行查询时会出现这个可爱的错误:
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
我完全不明白这个错误,我不知道如何解决它。怎么了?
注意:我了解什么是元类冲突是。我没有看到我是如何造成的:它似乎是在 MongoKit 内部的某个地方触发的。
【问题讨论】:
-
查看here 看看它是否有效。
-
当类的基础更改为与创建它们的内容不兼容时会发生这种情况。