【问题标题】:Django Oscar Image saved in cache folder but not showingDjango Oscar 图像保存在缓存文件夹中但未显示
【发布时间】:2021-08-17 21:03:42
【问题描述】:

谁能指出我解决图像无法正确显示的方向,因为图像保存在缓存文件夹中时出现 500 错误。我不确定是因为许可还是更深层次的原因?

这是我配置的,但不确定我是否正确。

URLS.py:

from django.apps import apps
from django.urls import include, path
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from oscar.views import handler403, handler404, handler500

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include(apps.get_app_config('oscar').urls[0])),
]

if settings.DEBUG:
    import debug_toolbar

    # Server statics and uploaded media
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    # Allow error pages to be tested
    urlpatterns += [
        path('403', handler403, {'exception': Exception()}),
        path('404', handler404, {'exception': Exception()}),
        path('500', handler500),
        path('__debug__/', include(debug_toolbar.urls)),
    ]

设置.py:

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

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

MEDIA_ROOT = '/media/'
MEDIA_URL = '/media/'

THUMBNAIL_DEBUG = DEBUG
THUMBNAIL_KEY_PREFIX = 'oscar-sandbox'
THUMBNAIL_KVSTORE = env(
    'THUMBNAIL_KVSTORE',
    default='sorl.thumbnail.kvstores.cached_db_kvstore.KVStore')
THUMBNAIL_REDIS_URL = env('THUMBNAIL_REDIS_URL', default=None)


STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
 
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

【问题讨论】:

    标签: python django django-oscar


    【解决方案1】:

    我遇到了同样的问题。我通过添加 urls.py 应用程序得到了帮助 网址字符串

    templates += static (settings. MEDIA_URL, document_root=settings. MEDIA_ROOT)
    

    在 settings.py 中也添加了:

    # Path helper
    location = lambda x: os.path.join(
        os.path.dirname(os.path.realpath(__file__)), x)
    
    # Absolute path to the directory that holds media.
    # Example: "/home/media/media.lawrence.com/"
    MEDIA_ROOT = location("public/media")
    
    # URL that handles the media served from MEDIA_ROOT. Make sure to use a
    # trailing slash if there is a path component (optional in other cases).
    # Examples: "http://media.lawrence.com", "http://example.com/media/"
    MEDIA_URL = '/media/'
    
    STATIC_URL = '/static/'
    STATIC_ROOT = location('public/static')
    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
    STATICFILES_DIRS = (
        location('static/'),
    )
    

    【讨论】:

      猜你喜欢
      • 2016-04-06
      • 1970-01-01
      • 2021-12-18
      • 2019-04-10
      • 2018-10-27
      • 2021-08-12
      • 1970-01-01
      • 2017-12-20
      相关资源
      最近更新 更多