Django ckeditor 图片上传 - 尝试上传图片时出现错误 403

Django ckeditor image upload - Error 403 when trying to upload images

我已经查看了所有关于使用 django ckeditor 上传图片的问题,但我找不到问题的解决方案。

我正在尝试使用 django ckeditor 为我的帖子启用图片上传,但我似乎遇到了问题,因为我在尝试上传它们时遇到了 403 错误。此外,如果我点击查看服务器,我会收到 404 错误,请参见屏幕截图 screenshot 1screenshot 2

这是我的代码:

urls.py

   urlpatterns = [
    url(r'^admin/', admin.site.urls),

    url(r'', include('pages.urls')),

    url(r'', include('blog.urls')),

    url(r'', include('staticpages.urls')),

    url(r'', include('shop.urls')),

    url(r'^ckeditor/', include('ckeditor_uploader.urls')),
] 

settings.py

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'core',
    'blog',
    'pages',
    'shop',
    'staticpages',
    'ckeditor',
    'ckeditor_uploader',
]
    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/2.0/howto/static-files/

    STATIC_URL = '/static/'
    STATICFILES_DIRS = ( os.path.join('static'), )
    STATIC_ROOT = "/home/username/myweb/static"

    # Media config

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


    ####################################
        ##  CKEDITOR CONFIGURATION ##
    ####################################

    CKEDITOR_JQUERY_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js'

    CKEDITOR_UPLOAD_PATH = 'uploads/'
    CKEDITOR_IMAGE_BACKEND = "pillow"


    CKEDITOR_IMAGE_BACKEND = "pillow"

    CKEDITOR_CONFIGS = {
        'default': {
            'toolbar': None,
        },
    }

models.py

from django.db import models
from django.utils.timezone import now
from django.urls import reverse
from ckeditor_uploader.fields import RichTextUploadingField

# Create your models here.

class StaticPage(models.Model):
    title = models.CharField(max_length=300, verbose_name="Title tag")
    description = models.CharField(max_length=300, blank=True, verbose_name="Description tag")
    slug_staticpage = models.SlugField(max_length=200, unique=True)
    h1 = models.CharField(max_length=300, blank=True, verbose_name="H1")
    content = RichTextUploadingField(blank=True, verbose_name="Contenido")
    published = models.DateTimeField(verbose_name="Publicado", default=now())
    created = models.DateField(auto_now_add=True, verbose_name="Creado")
    updated = models.DateTimeField(auto_now=True, verbose_name="Actualizado")

我做错了什么?我已经按照文档进行操作,但仍然无法弄清楚什么不起作用。

感谢这个很棒的社区的支持和帮助:)

歪斜

我也遇到了同样的问题。但我在 3 小时后解决了这个问题。将 ckeditor url 添加到所有 url 的顶部。对我有用

urlpatterns = [

    url(r'^ckeditor/', include('ckeditor_uploader.urls')),

    url(r'^admin/', admin.site.urls),

    url(r'', include('pages.urls')),

    url(r'', include('blog.urls')),

    url(r'', include('staticpages.urls')),

    url(r'', include('shop.urls')),


]