我无法使用whitenoise和压缩的静态文件(包括libsass)运行django项目。在下面的链接中,我看到只有通过离线压缩所需的静态文件才有可能。但是当我启动docker容器时,运行compress命令
docker-compose -f production.yml run --rm django python manage.py compress给了我错误:
ValueError: Missing staticfiles manifest entry for 'sass/app.scss'在尝试请求站点时,会出现以下错误(正如预期的那样?):
compressor.exceptions.OfflineGenerationError: You have offline compression enabled but key "..." is missing from offline manifest. You may need to run "python manage.py compress"设置如下(用炊具构建-django,参见下面完整的代码库链接):
STATIC_ROOT = str(ROOT_DIR("staticfiles"))
STATIC_URL = "/static/"
STATICFILES_DIRS = [str(APPS_DIR.path("static"))]
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
STATICFILES_FINDERS += ["compressor.finders.CompressorFinder"]
COMPRESS_PRECOMPILERS = [("text/x-scss", "django_libsass.SassCompiler")]
COMPRESS_CACHEABLE_PRECOMPILERS = (("text/x-scss", "django_libsass.SassCompiler"),)
COMPRESS_ENABLED = env.bool("COMPRESS_ENABLED", default=True)
COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage"
COMPRESS_URL = STATIC_URL所以在网上搜索了一天之后,我被困住了.如有任何帮助或建议!
代码库:都市/树/压缩
它是用炊具-django-基金会构建的
包括对config/setttings/production.py的下列更改
COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage" # Instead of pre-set "storages.backends.s3boto3.S3Boto3Storage"
COMPRESS_ROOT = STATIC_ROOT # Just in case
COMPRESS_OFFLINE = True # Needed to run compress offline可能的相关链接:
编辑
使用Justins的答案解决它(见下面,附加的更改)。我的错误是试图用已经在运行的容器压缩文件,给出了上面的错误。使用以下行更改Dockerfile之后(请注意重复的collectstatic cmd!):
python /app/manage.py collectstatic --noinput
python /app/manage.py compress --force
python /app/manage.py collectstatic --noinput
/usr/local/bin/gunicorn config.wsgi --bind 0.0.0.0:5000 --chdir=/app此外,与上述设置不同,我必须在设置/env文件中设置COMPRESS_ENABLED=True。
发布于 2019-11-20 18:56:00
我只是遇到了同样的问题。
将此添加到project/compose/production/django/start中
python /app/manage.py compress --force即
python /app/manage.py collectstatic --noinput
python /app/manage.py compress --force
/usr/local/bin/gunicorn config.wsgi --bind 0.0.0.0:5000 --chdir=/app发布于 2021-06-01 13:14:23
这很奇怪,但效果很好。
利用whitenoise收集和压缩静态文件
python manage.py collectstatic --clear将COMPRESS_STORAGE =COMPRESS_STORAGE设置为在缓存目录中生成.br文件
python manage.py compress --force将COMPRESS_STORAGE =COMPRESS_STORAGE设置为在缓存目录中生成.gzfiles
python manage.py compress --force要向whitenoise添加新的压缩文件: manifest.json、manifest.json.gz、manifest.json.br --非后处理选项是告诉whitenoise不要再次压缩静态文件。
python manage.py collectstatic --no-post-process确保按顺序运行这些命令。
测试whitenoise是否有效
python manage.py runserver --nostatichttps://stackoverflow.com/questions/58712195
复制相似问题