导入错误:没有名为模型的模块?
我正在使用 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因为它认为您引用的是同一目录中的
groups.py
。 启用绝对导入。Because it thinks that you're referring to the
groups.py
in the same directory. Enable absolute imports.我也遇到了同样的问题。解决方案就像 暗示一样简单
伊格纳西奥
I hade the same problem. The solution was as simple as
hinted by Ignacio
只是猜测,但是您的 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.