mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-03-03 19:08:15 +03:00
Merge pull request #2442 from jameswilliams1/fix-django-compressor-settings
Fix broken Django Compressor setup and enable static files minification
This commit is contained in:
commit
ca7fcb8f62
|
@ -131,6 +131,7 @@ Listed in alphabetical order.
|
|||
Irfan Ahmad `@erfaan`_ @erfaan
|
||||
Isaac12x `@Isaac12x`_
|
||||
Ivan Khomutov `@ikhomutov`_
|
||||
James Williams `@jameswilliams1`_
|
||||
Jan Van Bruggen `@jvanbrug`_
|
||||
Jelmer Draaijer `@foarsitter`_
|
||||
Jerome Caisip `@jeromecaisip`_
|
||||
|
@ -301,6 +302,7 @@ Listed in alphabetical order.
|
|||
.. _@howiezhao: https://github.com/howiezhao
|
||||
.. _@IanLee1521: https://github.com/IanLee1521
|
||||
.. _@ikhomutov: https://github.com/ikhomutov
|
||||
.. _@jameswilliams1: https://github.com/jameswilliams1
|
||||
.. _@ikkebr: https://github.com/ikkebr
|
||||
.. _@Isaac12x: https://github.com/Isaac12x
|
||||
.. _@iynaix: https://github.com/iynaix
|
||||
|
|
|
@ -31,11 +31,7 @@ DJANGO_GCP_STORAGE_BUCKET_NAME=
|
|||
# django-allauth
|
||||
# ------------------------------------------------------------------------------
|
||||
DJANGO_ACCOUNT_ALLOW_REGISTRATION=True
|
||||
{% if cookiecutter.use_compressor == 'y' %}
|
||||
# django-compressor
|
||||
# ------------------------------------------------------------------------------
|
||||
COMPRESS_ENABLED=
|
||||
{% endif %}
|
||||
|
||||
# Gunicorn
|
||||
# ------------------------------------------------------------------------------
|
||||
WEB_CONCURRENCY=4
|
||||
|
|
|
@ -6,4 +6,25 @@ set -o nounset
|
|||
|
||||
|
||||
python /app/manage.py collectstatic --noinput
|
||||
{% if cookiecutter.use_whitenoise == 'y' and cookiecutter.use_compressor == 'y' %}
|
||||
compress_enabled() {
|
||||
python << END
|
||||
import sys
|
||||
|
||||
from environ import Env
|
||||
|
||||
env = Env(COMPRESS_ENABLED=(bool, True))
|
||||
if env('COMPRESS_ENABLED'):
|
||||
sys.exit(0)
|
||||
else:
|
||||
sys.exit(1)
|
||||
|
||||
END
|
||||
}
|
||||
|
||||
if compress_enabled; then
|
||||
# NOTE this command will fail if django-compressor is disabled
|
||||
python /app/manage.py compress
|
||||
fi
|
||||
{%- endif %}
|
||||
/usr/local/bin/gunicorn config.wsgi --bind 0.0.0.0:5000 --chdir=/app
|
||||
|
|
|
@ -201,9 +201,27 @@ ANYMAIL = {
|
|||
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_ENABLED
|
||||
COMPRESS_ENABLED = env.bool("COMPRESS_ENABLED", default=True)
|
||||
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE
|
||||
{%- if cookiecutter.cloud_provider == 'AWS' %}
|
||||
COMPRESS_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"
|
||||
{%- elif cookiecutter.cloud_provider == 'GCP' %}
|
||||
COMPRESS_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
|
||||
{%- elif cookiecutter.cloud_provider == 'None' %}
|
||||
COMPRESS_STORAGE = "compressor.storage.GzipCompressorFileStorage"
|
||||
{%- endif %}
|
||||
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL
|
||||
COMPRESS_URL = STATIC_URL{% if cookiecutter.use_whitenoise == 'y' or cookiecutter.cloud_provider == 'None' %} # noqa F405{% endif %}
|
||||
{%- if cookiecutter.use_whitenoise == 'y' %}
|
||||
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
|
||||
COMPRESS_OFFLINE = True # Offline compression is required when using Whitenoise
|
||||
{%- endif %}
|
||||
# https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_FILTERS
|
||||
COMPRESS_FILTERS = {
|
||||
"css": [
|
||||
"compressor.filters.css_default.CssAbsoluteFilter",
|
||||
"compressor.filters.cssmin.rCSSMinFilter",
|
||||
],
|
||||
"js": ["compressor.filters.jsmin.JSMinFilter"],
|
||||
}
|
||||
{% endif %}
|
||||
{%- if cookiecutter.use_whitenoise == 'n' -%}
|
||||
# Collectfast
|
||||
|
|
Loading…
Reference in New Issue
Block a user