我正在尝试按照https://docs.djangoproject.com/en/dev/ref/applications/上的文档为我的一个名为“articles”的 Django 应用程序设置自定义应用程序配置,但我ImportError: No module named articles.apps
在执行时不断获取./manage.py check
(或任何其他管理命令,例如./manage.py runserver
)
这是项目的树
projectname
├── apps
│ ├── articles
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── __init__.py
│ │ ├── migrations
│ │ │ ├── 0001_initial.py
│ │ │ └── __init__.py
│ │ ├── models.py
│ │ ├── templates
│ │ │ └── articles
│ │ ├── templatetags
│ │ │ ├── articles_tags.py
│ │ │ └── __init__.py
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── __init__.py
在settings.py中安装的应用程序:
INSTALLED_APPS = (
'grappelli',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'grappelli.dashboard',
'mptt',
'sekizai',
'pytils',
'sorl.thumbnail',
'sefaro.apps.utils',
'sefaro.apps.seo',
'sefaro.apps.staticpages',
'sefaro.apps.statictext',
'sefaro.apps.usersettings',
'sefaro.apps.navigation',
'sefaro.apps.slideshow',
'sefaro.apps.articles',
)
内容articles/__init__.py
:
# articles/__init__.py
default_app_config = 'articles.apps.ArticlesConfig'
内容articles/apps.py
:
# -*- coding: utf-8 -*-
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class ArticlesConfig(AppConfig):
name = 'articles'
verbose_name = _(u'Articles')
我'projectname.apps.articles'
在我的INSTALLED_APPS
只是为了确保我真的拥有所有这些文件并且没有弄乱路径
>>> from projectname.apps.articles.apps import ArticlesConfig
>>> ArticlesConfig
<class 'projectname.apps.articles.apps.ArticlesConfig'>
一切都很好进口...
但:
(vagrant)vagrant@vagrant-ubuntu-trusty-32:~/django$ ./manage.py check
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/vagrant/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/vagrant/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/vagrant/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/vagrant/local/lib/python2.7/site-packages/django/apps/config.py", line 112, in create
mod = import_module(mod_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named articles.apps