我在Django工作,通过Heroku部署,试图将WhiteNoise用于静态资产。
我有一个CSS文件,它引用一个用作背景的图像:
body { background: white url("images/nyc.jpg") left top; }
当我在本地加载页面时,背景图像会完美显示。
但是,当我部署到Heroku时(使用本地计算机上的git push),背景图像不会显示在页面上。当我向Heroku执行git推送时收到此错误消息:
Traceback (most recent call last):
whitenoise.django.MissingFileError: The file 'multiblog/images/nyc.jpg' could not be found with <whitenoise.django.GzipManifestStaticFilesStorage object at 0x7fab5c4fb210>.
The CSS file 'multiblog/style.css' references a file which could not be found:
Please check the URL references in this CSS file, particularly any
relative paths which might be pointing to the wrong location.
以下是我的项目级别settings.py中的相关行(如果需要,很乐意分享更多内容):
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
BASE_DIR2 = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR2, 'static'),
]
# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
答案 0 :(得分:0)
答案 1 :(得分:0)
在您提供的屏幕截图中,文件名为nyc.JPG
,而您的代码引用nyc.jpg
。文件名区分大小写:)