【发布时间】:2019-10-02 04:11:13
【问题描述】:
我正在尝试在我的产品评论网站中提供静态文件,并且我正在使用 Whitenoise,但它不起作用(无法在 /static 中找到文件)(当我在本地使用 DEFAULT = False 进行测试时,它仍然有效)
我尝试配置 wsgi 文件而不是使用白噪声中间件
这是我的设置文件中的一些代码,用于提供静态服务。
DEBUG = False
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
...
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'djangobower.finders.BowerFinder',
)
你能告诉我如何解决它吗?请原谅我的英语
我尝试再次配置设置:
DEBUG = False
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
...
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# I don't have STATICFILES_DIRS, is it wrong?
STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'djangobower.finders.BowerFinder',
)
但还是不能提供静态文件
【问题讨论】:
-
如果在本地机器上测试结果不一样,能否分享一下nginx/Apache的配置,看看有没有什么问题会干扰?
标签: django product whitenoise