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
Fi开发者_如何学运维le "/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
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
from __future__ import absolute_import
hinted by Ignacio
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.
精彩评论