【问题标题】:Django Ckeditor File Upload - Error With Path?Django Ckeditor 文件上传 - 路径错误?
【发布时间】:2020-10-13 14:46:04
【问题描述】:

我正在尝试使用ckeditor_uploader,并在尝试从管理仪表板上传图片时收到以下错误。

img-5485.JPG:1 GET https://fixmybike-staging.herokuapp.com/media/uploads/2020/06/23/img-5485.JPG 404 (Not Found)

我在本地运行服务器时上传文件没有问题,所以我假设这与 Heroku 如何处理媒体路径以及我如何配置它有关。

base.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'bikemech',
    'ckeditor',
    'ckeditor_uploader',
]

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

CKEDITOR_UPLOAD_PATH = "uploads/"


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

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

我也已经在使用'whitenoise.middleware.WhiteNoiseMiddleware',

urls.py

from django.contrib import admin
from django.urls import path, include
from bikemech import views
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('ckeditor', include("ckeditor_uploader.urls")),
    path('', include('bikemech.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

我从其他堆栈溢出帖子中尝试了base.py 中的各种配置,但没有成功。此外,Heroku 成功运行 collectstatic,所以我认为这不是问题所在。

【问题讨论】:

  • 尝试我在下面完成的re_path 方法。

标签: python django heroku ckeditor content-management-system


【解决方案1】:

检查这种方法是否可以帮助您。还要检查一下,heroku 确实允许在其免费服务中长时间渲染图像。

settings.py

CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_JQUERY_URL = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'
CKEDITOR_IMAGE_BACKEND = 'pillow'

#config for differnt type of WYSIWYG functionalities
CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': None,
    },
 }

主 urls.py:

from django.urls import path, include, re_path


urlpatterns = [
    path('admin/', admin.site.urls),
    ...

    path('search/', ex...)),
    path('chekout/', ex...),
    re_path(r'^ckeditor/', include('ckeditor_uploader.urls')),
]

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

【讨论】:

    猜你喜欢
    • 2021-07-28
    • 2016-02-25
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 2012-05-18
    • 2010-12-31
    • 1970-01-01
    • 2015-10-22
    相关资源
    最近更新 更多