简体   繁体   English

Whitenoise静态文件上传不适用于DEBUG = False

[英]Whitenoise static file upload not working with DEBUG=False

I have a Django web app and I serve static files with Whitenoise. 我有一个Django Web应用程序,并且使用Whitenoise提供静态文件。 The problem is that I can't upload and get images when DEBUG=False . 问题是当DEBUG=False时,我无法上传和获取图像。 Everything work well with DEBUG=True but when I disable it, uploading is not working anymore but retrieving images works. DEBUG=True时一切正常,但是当我禁用它时,上传不再起作用,但检索图像仍然有效。

Here is my whitenoise configuration : 这是我的白噪声配置:

wsgi.py wsgi.py

from whitenoise.django import DjangoWhiteNoise
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
application = DjangoWhiteNoise(application)

and settings.py 和settings.py

MEDIA_ROOT = os.path.join(BASE_DIR, 'public/static/public/images')
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
STATIC_URL = '/static/'
STATIC_ROOT = 'public/static/'

Whitenoise isn't designed for serving media files. Whitenoise不适用于提供媒体文件。 It scans the directory at startup, and assumes that the files will not change while the application runs. 它在启动时扫描目录,并假定在应用程序运行时文件不会更改。

See issue 32 for more information. 有关更多信息,请参见第32期。

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

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