5

我开始了这个 Turial,在这里

并得到这个错误

**mongoengine.errors.NotRegistered:** `Comment` has not been registered in the document registry. Importing the document class automatically registers it, has it been imported?

任何想法。太感谢了。

4

2 回答 2

3

只需将评论模型放在帖子模型之上,因为评论模型在帖子模型中被引用

于 2015-04-16T15:28:40.193 回答
3

__init__.py首先在你的models包中注册你所有的模型。

然后您可以使用get_document('Comment')函数(从 导入mongoengine.base.common)而不是在其他脚本中导入您的模型,以避免循环导入和异常,例如mongoengine.errors.NotRegistered

于 2016-01-05T14:56:23.970 回答