【问题标题】:Django-ckeditor file upload doesn't workDjango-ckeditor 文件上传不起作用
【发布时间】:2016-01-29 19:52:57
【问题描述】:

我在我的博客中使用 django-ckeditor 模块作为所见即所得的编辑器,用于在管理中创建和编辑文章。它工作得很好,但我无法将图像上传到我的服务器。当我单击图像按钮时,“浏览服务器”和“上传图像”按钮没有按预期显示(我在某处看到过)。我只能添加提供其网址的外部图像。 我将 Django 1.8 与 Python 3.4 一起使用

模块 django-ckeditor 和 ckeditor_uploader 已正确安装并添加到 INSTALLED_APP 中。

这是我的 settings.py 文件:

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
    'ckeditor',
    'ckeditor_uploader',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'django-mini-blog.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
            ],
        },
    },
]

WSGI_APPLICATION = 'django-mini-blog.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

LANGUAGE_CODE = 'fr-fr'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'

MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

CKEDITOR_UPLOAD_PATH = "uploads/"

CKEDITOR_IMAGE_BACKEND = "pillow"

提前感谢您的帮助。

此致,

【问题讨论】:

    标签: django python-3.x django-ckeditor


    【解决方案1】:

    您是否将以下代码添加到您的 urls.py 文件中?

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

    【讨论】:

    • 我的项目 urls.py 中有 url(r'^ckeditor/', include('ckeditor_uploader.urls')),。 ckeditor.urls 无法识别,我使用它时遇到 ImportError:没有名为“ckeditor.urls”的模块
    • 你用的是什么版本?
    • 在 4.5.1 (pypi.python.org/pypi/django-ckeditor) 之后的版本中进行了一些向后不兼容的更改。我相信您的设置对于 4.5.1 版本是正确的 或者将您的 urls.py 更改为 (r'^ckeditor/', include('ckeditor_uploader.urls'))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-07
    • 1970-01-01
    • 2023-04-07
    • 2020-10-13
    • 2020-10-21
    • 2010-10-07
    • 1970-01-01
    相关资源
    最近更新 更多