无法使用Djangocketditor上载图像(错误400)

2024-09-28 16:20:13 发布

您现在位置:Python中文网/ 问答频道 /正文

当我想在CKEditor中上载图像时,它会显示错误“文件上载期间发生HTTP错误(错误状态:400)”

请检查下面的图片

Image

内部URL.py

from django.contrib import admin

from django.urls import path,include
from django.conf import settings
from django.conf.urls import url
from django.conf.urls.i18n import i18n_patterns
from django.conf.urls.static import static


urlpatterns = i18n_patterns(
    ....
    path('ckeditor/',include('ckeditor_uploader.urls')),
    ....
    )



if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

内部设置.py--->;对于CKEDITOR

INSTALLED_APPS = [
    ...,
    'ckeditor',
    'ckeditor_uploader',
    ...,
    
    
]

#Ckeditor


CKEDITOR_IMAGE_BACKEND = "pillow"

CKEDITOR_UPLOAD_PATH="uploads/"


CKEDITOR_CONFIGS={

     'myconfig':{
        'toolbar':"Custom",
    'toolbar_Custom':[

    ['Styles','Format','Font','FontSize','BidiLtr','BidiRtl'],
    ['JustifyLeft','JustifyCenter','JustifyRight','NumberedList', 'BulletedList','Bold','Italic','Underline','Strike','Undo','Redo'],
    ['Link','Unlink','Anchor'],
    ['TextColor','BGColor'],
    ['Smilely','SpecialChar'],
    ['Source','Scayt','Maximize'],
    ['Table','Templates','Iframe','Image'],
    ],
    'height': 100,
    },

}

在models.py中

 content = RichTextUploadingField(config_name='myconfig')

你能帮我吗


1条回答
网友
1楼 · 发布于 2024-09-28 16:20:13

若要上载图像,请尝试以下操作

pip install django-ckeditor // or just make sure it is installed

在设置中:

INSTALLED_APPS = [
    ...
    'ckeditor',
    'ckeditor_uploader',
],

// at the bottom of the file add

CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_IMAGE_BACKEND = "pillow"

在主URL中:

 path('ckeditor/', include('ckeditor_uploader.urls')),

在你的模型中.py

from ckeditor_uploader.fields import RichTextUploadingField

body = RichTextUploadingField(blank=True, null=True) // body, image, or whatever name  you choose.

应该这样做

相关问题 更多 >