0
CKeditor由于某些原因无法在从设置中加载时找到,但是从python shell导入它工作正常。Django无法在设置中导入ckeditor,但可以在shell中导入?
Django 1.7。 Python(2.7.9)是一个备用安装。通过pip2.7 install django-ckeditor
https://github.com/django-ckeditor/django-ckeditor
settings.py中安装的CKEditor没有CKEditor的:
[[email protected] mysite]$ python2.7 manage.py shell
Python 2.7.9 (default, Feb 1 2015, 21:31:28)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import ckeditor
>>>
>>>
>>>
[[email protected] mysite]$ python2.7 manage.py collectstatic
You have requested to collect static files at the destination
location as specified in your settings:
/var/www/mysite/static
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
0 static files copied to '/var/www/mysite/static', 2357 unmodified.
加入 'CKEditor的'到的settings.py:
INSTALLED_APPS = (
'ckeditor ',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'allauth',
'documentation',
'allauth.account',
'allauth.socialaccount',
'django.contrib.auth',
'app',
'thunderdome',
'suit',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
# 'supplementtut',
'dbmail',
'tinymce',
)
CKEDITOR_UPLOAD_PATH = "uploads/"
壳牌,collectstatic,runserver命令都是一样的:
[[email protected] mysite]$ python2.7 manage.py collectstatic
Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 87, in create
module = import_module(entry)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named ckeditor
[[email protected] mysite]$
验证它的安装:
[[email protected] mysite]$ cd /usr/local/lib/python2.7/site-packages/ckeditor
[[email protected] ckeditor]$ ls -l
total 92
-rw-r--r-- 1 user domain users 1371 Apr 6 13:03 fields.py
-rw-r--r-- 1 user domain users 1975 Apr 6 13:03 fields.pyc
drwxr-xr-x 2 user domain users 4096 Apr 6 13:03 image
-rw-r--r-- 1 user domain users 297 Apr 6 13:03 image_processing.py
-rw-r--r-- 1 user domain users 611 Apr 6 13:03 image_processing.pyc
-rw-r--r-- 1 user domain users 721 Apr 6 13:03 __init__.py
-rw-r--r-- 1 user domain users 853 Apr 6 13:03 __init__.pyc
drwxr-xr-x 3 user domain users 4096 Apr 6 13:03 management
-rw-r--r-- 1 user domain users 0 Apr 6 13:03 models.py
-rw-r--r-- 1 user domain users 144 Apr 6 13:03 models.pyc
drwxr-xr-x 3 user domain users 4096 Apr 6 13:03 static
drwxr-xr-x 3 user domain users 4096 Apr 6 13:03 templates
-rw-r--r-- 1 user domain users 411 Apr 6 13:03 urls.py
-rw-r--r-- 1 user domain users 649 Apr 6 13:03 urls.pyc
-rw-r--r-- 1 user domain users 1025 Apr 6 13:03 utils.py
-rw-r--r-- 1 user domain users 2207 Apr 6 13:03 utils.pyc
-rw-r--r-- 1 user domain users 4749 Apr 6 13:03 views.py
-rw-r--r-- 1 user domain users 5089 Apr 6 13:03 views.pyc
-rw-r--r-- 1 user domain users 4583 Apr 6 13:03 widgets.py
-rw-r--r-- 1 user domain users 4957 Apr 6 13:03 widgets.pyc
[[email protected] ckeditor]$
更新: 检查以验证它被安装:
皮普冻结:
[[email protected] mysite]$ pip2.7 freeze | grep ckeditor
django-ckeditor==4.4.7
你可以使用:'pip freeze | grep ckeditor'来验证django-ckeditor是否被实际安装。另外,检查'CKEDITOR_UPLOAD_PATH'变量是否在settings.py中设置。 – slackmart
新增了您建议的相同结果。 – BilliAm
啧啧,它看起来很好。我建议你使用虚拟环境来隔离你的项目;因为你使用的是Python 2.7.9,你应该使用virtualenv(你知道'pip2.7 install virtualenv'),然后使用'virtualenv my_virtual_env'创建一个虚拟环境,然后激活虚拟环境:'source my_virtual_env/bin /激活',然后安装你要在你的项目中使用的模块,例如'pip install django == 1.7 django-ckeditor'。最后用'django-admin.py startproject project_name'创建你的项目。 – slackmart