gpt4 book ai didi

django - 导入错误 : cannot import name MPTTModel

转载 作者:行者123 更新时间:2023-12-05 00:33:04 25 4
gpt4 key购买 nike

我做了教程“http://django-mptt.github.com/django-mptt/tutorial.html”中的步骤

但它仍然给我导入错误,我仔细检查了 mptt 的代码,发现 mptt>model 文件中存在类 MPTTMODEL

Validating models...

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x1ec4710>>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/core/management/validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 158, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 67, in _populate
self.load_app(app_name)
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/db/models/loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "/usr/local/lib/python2.7/dist-packages/Django-1.4-py2.7.egg/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/kareemhashem/espace/sharek/core/models.py", line 12, in <module>
from mptt.models import MPTTModel, TreeForeignKey
ImportError: cannot import name MPTTModel

最佳答案

您可以尝试一件事:转到控制台并输入:python (获取python控制台)然后输入:from mptt.models import MPTTModel
如果这给您一个错误,则 mptt 未正确安装。

如果您正在使用 pip你可以轻松做到:pip install django-mptt或者你可以试试 pip install django-mptt --upgrade更新您的安装。可能是你的安装没有成功。

如果您不使用 pip 或 virtualenv,我强烈推荐它。开始有点艰难,但更糟糕的是安装它。请参阅以下资源以开始使用:1 , 2

如果您已经成功安装了mptt,但仍然无法导入,则可能是python无法访问您放置mptt的文件夹。因此,将 mptt 所在的路径添加到您的 PYTHONPATH。看到这个 thread怎么做。

关于django - 导入错误 : cannot import name MPTTModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12585993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com