我正在开发一个简单的django应用程序,但我遇到了一个导入问题。这是我的文件夹结构:
django_intuitive_pagination/
├── example
│ ├── config
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── items
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── __init__.py
│ │ ├── migrations/
│ │ ├── models.py
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ └── manage.py
├── intuitive_pagination
│ ├── __init__.py
│ ├── mixins.py
│ ├── paginator.py
│ ├── templates/
│ ├── templatetags/
│ └── views.py
├── runtests.py
└── tests/
我在intuitive_pagination
中添加example.config.settings.py
作为django应用。添加example.items.views.py
,我还从class
导入intuitive_pagination.views.py
。但是,当我运行python manage.py
命令时,django投诉ImportError: No module named 'intuitive_pagination'
:
example/config/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'items',
'intuitive_pagination',
]
example/items/views.py
from intuitive_pagination.views import PaginationListView
...
我确信项目的顶层是在python路径中完成的
>>> sys.path
[..., '/home/light/Workspace/PycharmProjects/DjangoProjects/django_intuitive_pagination']
完整筹码:
Traceback (most recent call last):
File "/home/light/.virtualenvs/intuitive_pagination/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/home/light/.virtualenvs/intuitive_pagination/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
autoreload.raise_last_exception()
File "/home/light/.virtualenvs/intuitive_pagination/lib/python3.5/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/home/light/.virtualenvs/intuitive_pagination/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/light/.virtualenvs/intuitive_pagination/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/home/light/.virtualenvs/intuitive_pagination/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/light/.virtualenvs/intuitive_pagination/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/light/.virtualenvs/intuitive_pagination/lib/python3.5/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/home/light/.virtualenvs/intuitive_pagination/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 985, in _gcd_import
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
ImportError: No module named 'intuitive_pagination'
为什么django不能导入intuitive_pagination
模块?