Django:在INSTALLED_APPS中找到第四方应用程序的问题

时间:2015-10-30 17:37:14

标签: python django

当我使用库运行服务器时,我在manage.py文件中出现此错误" ckeditor" (我也和tinymce有同样的错误):

Traceback (most recent call last):                                                                                                  
  File "manage.py", line 10, in <module>                                                                                            
    execute_from_command_line(sys.argv)                                                                                             
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line          
    utility.execute()                                                                                                               
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute                            
    django.setup()                                                                                                                  
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup                                               
    apps.populate(settings.INSTALLED_APPS)                                                                                          
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate                                       
    app_config = AppConfig.create(entry)                                                                                            
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 86, in create                                           
    module = import_module(entry)                                                                                                   
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module                                                        
    __import__(name)                                                                                                                
ImportError: No module named ckeditor_uploader

在shell模式下导入此库没有问题。我还检查了shell中的路径,sys可以访问&#34; site-packages&#34;安装的地方:

$ python manage.py shell
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from ckeditor.fields import RichTextField
>>>
>>> import sys
>>> for x in sys.path: print x 
... 
...
/home/ubuntu/workspace/venv/local/lib/python2.7/site-packages
/home/ubuntu/workspace/venv/lib/python2.7/site-packages

我查看了使用pip list和&#34; django-ckeditor&#34;安装的库列表。在那儿。

我的一些文件:

manage.py:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings")
    from django.core.management import execute_from_command_line
    execute_from_command_line(sys.argv)

setting.py:

INSTALLED_APPS = (
    'django.contrib.admin',
    ...
    'myapp',
    'ckeditor_uploader',
)
...
CKEDITOR_CONFIGS = {
    'awesome_ckeditor': {
        'toolbar': 'Basic',
    },
}

Pip冻结

$ pip freeze
dj-database-url==0.3.0
dj-static==0.0.6
Django==1.8.5
django-ckeditor==5.0.2
django-toolbelt==0.0.1
gunicorn==19.3.0
psycopg2==2.6.1
static3==0.5.1
virtualenv==13.1.2
wheel==0.26.0

urls.py

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', include('myapp.urls')),
    url(r'^ckeditor/', include('ckeditor_uploader.urls') ),
]

我读了一篇由旧版本的pip引起类似问题的帖子,但我升级了它。

2 个答案:

答案 0 :(得分:1)

将设置中已安装的应用更改为:

settings.py:

INSTALLED_APPS = (
    'django.contrib.admin',
    ...
    'myapp',
    'ckeditor',
)
...
CKEDITOR_CONFIGS = {
    'awesome_ckeditor': {
        'toolbar': 'Basic',
    },
}

另请记得将ckeditor添加到您的urls.py

urlpatterns = patterns(
    '',
    ...
    (r'^ckeditor/', include('ckeditor_uploader.urls')),
    ...
)

答案 1 :(得分:0)

关注https://pypi.python.org/pypi/django-ckeditor/5.0.2

Add ``ckeditor`` to your ``INSTALLED_APPS`` setting.

是必需的。

Add ``ckeditor_uploader`` to your ``INSTALLED_APPS`` setting.
使用带文件上传的小部件需要

ckeditorckeditor_uploader添加到INSTALLED_APPS

Add a CKEDITOR_UPLOAD_PATH setting to the project's settings.py file.