简体   繁体   English

Django Ckeditor 文件上传 - 路径错误?

[英]Django Ckeditor File Upload - Error With Path?

I'm trying to use ckeditor_uploader and receiving the following error when attempting to upload an image from the admin dashboard.我正在尝试使用ckeditor_uploader并在尝试从管理仪表板上传图像时收到以下错误。

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

I have no issues uploading a file when I run the server locally, so I'm assuming this is related to how Heroku handles media paths and how I've configured it.当我在本地运行服务器时上传文件没有问题,所以我假设这与 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/')

I'm also already using 'whitenoise.middleware.WhiteNoiseMiddleware',我也已经在使用'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)

I've attempted a variety of configurations in base.py from other stack overflow posts with no luck.我从其他堆栈溢出帖子中尝试了base.py中的各种配置,但没有成功。 Also, Heroku is succeeding at running collectstatic so I don't believe that's the issue.此外,Heroku 正在成功运行collectstatic ,所以我认为这不是问题所在。

Check if this approach can help you.检查这种方法是否可以帮助您。 Also check, heroku doens allow images be rendered for long in its free service.另请检查,heroku 确实允许在其免费服务中长时间渲染图像。

settings.py设置.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,
    },
 }

main urls.py:主要网址.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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM