关于python:django监护人importerror但其他例子工作

django guardian importerror but other examples work

首先,我是django和python的新手。

我正在研究一个使用django-guardian 1.3.2的现有项目。 我验证了此应用程序部署的服务器也通过pip list使用1.3.2。

我试图了解异常的原因。

有现有的admin.py文件,加载就好了。

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/env python
# coding: utf-8
from guardian.admin import GuardedModelAdmin
from django.contrib import admin

from devices import models


class SomeModelAdmin(GuardedModelAdmin):
  pass


admin.site.register(models.SomeModel, SomeModelAdmin)

我添加了我的,这也适用(在我的机器上)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python
# coding: utf-8
from guardian.admin import GuardedModelAdmin


from django.contrib import admin
from common import models


class MyModel1Admin(GuardedModelAdmin):
    pass


admin.site.register(models.MyModel1, MyModel1Admin)


class MyModel2Admin(GuardedModelAdmin):
    pass


admin.site.register(models.MyModel2, MyModel2Admin)

我们部署了应用程序,现在它无法启动以下异常:

Traceback (most recent call last): File
"/usr/local/share/.virtualenvs/my_app/lib/python2.7/site-packages/django/core/handlers/wsgi.py",
line 187, in call
self.load_middleware() File"/usr/local/share/.virtualenvs/my_app/lib/python2.7/site-packages/django/core/handlers/base.py",
line 47, in load_middleware
mw_instance = mw_class() File"/usr/local/share/.virtualenvs/my_app/lib/python2.7/site-packages/django/middleware/locale.py",
line 24, in init
for url_pattern in get_resolver(None).url_patterns: File"/usr/local/share/.virtualenvs/my_app/lib/python2.7/site-packages/django/core/urlresolvers.py",
line 365, in url_patterns
patterns = getattr(self.urlconf_module,"urlpatterns", self.urlconf_module) File
"/usr/local/share/.virtualenvs/my_app/lib/python2.7/site-packages/django/core/urlresolvers.py",
line 360, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name) File"/usr/local/share/.virtualenvs/my_app/lib/python2.7/site-packages/django/utils/importlib.py",
line 40, in import_module
import(name) File"./sites/zpanel/urls.py", line 19, in
admin.autodiscover() File"/usr/local/share/.virtualenvs/my_app/lib/python2.7/site-packages/django/contrib/admin/init.py",
line 29, in autodiscover
import_module('%s.admin' % app) File"/usr/local/share/.virtualenvs/my_app/lib/python2.7/site-packages/django/utils/importlib.py",
line 40, in import_module
import(name) File"./common/admin.py", line 3, in
from guardian.admin import GuardedModelAdmin ImportError: No module named admin

服务器正在运行python 2.7.6,我使用的是2.7.10。 我不认为这是一个问题,因为从guardina.admin导入其他admin.py文件就好了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'sites.this_app',
    'notifications.email',
    'raven.contrib.django.raven_compat',
    'guardian',
    'my_stuff',
    'existing_ones'
    'rest_framework',
    'rest_framework.authtoken',
    'south',
    'djangular',
    'widget_tweaks',
    'djrill',
    'corsheaders',
    'django_extensions',
    'parler',
    'watson',
    'baldr',
)


事实证明,在与我的admin.py文件相同的目录中有一个名为guardian的目录。 此目录不在源(不再)中,也不在我的本地计算机上。 我想这是很久以前某些部署的残留......