导入错误:没有名为模型的模块?

发布于 2024-11-25 03:53:58 字数 2066 浏览 0 评论 0 原文

我正在使用 Django,并且我的组应用程序不断收到此错误,我已经检查了所有导入设置,一切都很好。我的注册和个人资料应用程序运行顺利,但为什么这个应用程序给我一个模型导入错误?

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 219, in execute
    self.validate()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 249, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py", line 36, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
    self._populate()
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 64, in _populate
    self.load_app(app_name)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 78, in load_app
    models = import_module('.models', app_name)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/gladiator/django_projects/classes/groups/models.py", line 6, in <module>
    from groups.shortcuts import build_filename
  File "/home/gladiator/django_projects/classes/groups/groups.py", line 5, in <module>
  File "/home/gladiator/django_projects/classes/groups/decorators.py", line 2, in <module>
    from groups.models import Group, GroupMember
ImportError: No module named models

I am using Django and I keep receiving this error for my group app, I have checked all my import settings and everything is fine. My registration and profile apps run smoothly but why is this app giving me an ImportError for models?

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 219, in execute
    self.validate()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 249, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/validation.py", line 36, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
    self._populate()
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 64, in _populate
    self.load_app(app_name)
  File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 78, in load_app
    models = import_module('.models', app_name)
  File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/gladiator/django_projects/classes/groups/models.py", line 6, in <module>
    from groups.shortcuts import build_filename
  File "/home/gladiator/django_projects/classes/groups/groups.py", line 5, in <module>
  File "/home/gladiator/django_projects/classes/groups/decorators.py", line 2, in <module>
    from groups.models import Group, GroupMember
ImportError: No module named models

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

如梦亦如幻 2024-12-02 03:53:58

因为它认为您引用的是同一目录中的groups.py启用绝对导入

Because it thinks that you're referring to the groups.py in the same directory. Enable absolute imports.

冰之心 2024-12-02 03:53:58

我也遇到了同样的问题。解决方案就像 暗示一样简单

from __future__ import absolute_import

伊格纳西奥

I hade the same problem. The solution was as simple as

from __future__ import absolute_import

hinted by Ignacio

岛徒 2024-12-02 03:53:58

只是猜测,但是您的 models.py 文件是否导入组或装饰器?如果是这样,则存在循环依赖。您需要将其中一个文件中的导入移至函数级别。

Just a guess, but does your models.py file import groups or decorators? If so, you have a circular dependency. You'll need to move the imports in one of the files into the function level.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文