mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-01-23 15:54:12 +03:00
Add django-compressor suport (#568)
* #342 Add compressor option to requirements * #342 Add compressor to production settings * #342 Add compressor to base template * #342 Add settings to common.py and add tags to base template * #342 Flake8 fix for tox tests * #342 Remove redundant line * #342 Add required options for S3 to production.py and added Env variable to enable/disable compression * #342 Add required options for compressor on S3 to production.py
This commit is contained in:
parent
e085b40ab5
commit
3d2385a3b6
|
@ -17,6 +17,7 @@
|
|||
"use_python2": "n",
|
||||
"use_docker": "y",
|
||||
"use_heroku": "n",
|
||||
"use_compressor": "n",
|
||||
"js_task_runner": ["Gulp", "Grunt", "None"],
|
||||
"use_lets_encrypt": "n",
|
||||
"open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"]
|
||||
|
|
|
@ -233,6 +233,13 @@ BROKER_URL = env('CELERY_BROKER_URL', default='django://')
|
|||
########## END CELERY
|
||||
{% endif %}
|
||||
|
||||
# django-compressor
|
||||
# ------------------------------------------------------------------------------
|
||||
{% if cookiecutter.use_compressor == 'y'-%}
|
||||
INSTALLED_APPS += ("compressor", )
|
||||
STATICFILES_FINDERS += ("compressor.finders.CompressorFinder", )
|
||||
{%- endif %}
|
||||
|
||||
# Location of root django.contrib.admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %}
|
||||
ADMIN_URL = r'^admin/'
|
||||
|
||||
|
|
|
@ -140,14 +140,19 @@ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
|||
{% else %}
|
||||
STATIC_URL = 'https://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME
|
||||
STATICFILES_STORAGE = 'config.settings.production.StaticRootS3BotoStorage'
|
||||
|
||||
# See: https://github.com/antonagestam/collectfast
|
||||
# For Django 1.7+, 'collectfast' should come before
|
||||
# 'django.contrib.staticfiles'
|
||||
AWS_PRELOAD_METADATA = True
|
||||
INSTALLED_APPS = ('collectfast', ) + INSTALLED_APPS
|
||||
{%- endif %}
|
||||
|
||||
{% if cookiecutter.use_compressor == 'y'-%}
|
||||
# COMPRESSOR
|
||||
# ------------------------------------------------------------------------------
|
||||
COMPRESS_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
|
||||
COMPRESS_URL = STATIC_URL
|
||||
COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True)
|
||||
{%- endif %}
|
||||
# EMAIL
|
||||
# ------------------------------------------------------------------------------
|
||||
DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
|
||||
|
|
|
@ -31,3 +31,6 @@ DJANGO_OPBEAT_ORGANIZATION_ID
|
|||
DJANGO_OPBEAT_APP_ID
|
||||
DJANGO_OPBEAT_SECRET_TOKEN
|
||||
{% endif %}
|
||||
{% if cookiecutter.use_compressor == 'y' -%}
|
||||
COMPRESS_ENABLED=
|
||||
{% endif %}
|
|
@ -54,4 +54,8 @@ redis>=2.10.0
|
|||
celery==3.1.23
|
||||
{% endif %}
|
||||
|
||||
{% if cookiecutter.use_compressor == "y" %}
|
||||
django_compressor==2.0
|
||||
{% endif %}
|
||||
|
||||
# Your custom requirements go here
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% raw %}{% load staticfiles i18n %}<!DOCTYPE html>
|
||||
{% raw %}{% load staticfiles i18n {% endraw %}{% if cookiecutter.use_compressor == "y" %}compress{% endif %}{% raw %}%}<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
@ -18,9 +18,10 @@
|
|||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
|
||||
|
||||
<!-- Your stuff: Third-party css libraries go here -->
|
||||
|
||||
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress css %}{% endraw %}{% endif %}{% raw %}
|
||||
<!-- This file store project specific CSS -->
|
||||
<link href="{% static 'css/project.css' %}" rel="stylesheet">
|
||||
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %}
|
||||
{% endblock %}
|
||||
|
||||
</head>
|
||||
|
@ -100,7 +101,10 @@
|
|||
<!-- Your stuff: Third-party javascript libraries go here -->
|
||||
|
||||
<!-- place project specific Javascript in this file -->
|
||||
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress js %}{% endraw %}{% endif %}{% raw %}
|
||||
<script src="{% static 'js/project.js' %}"></script>
|
||||
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %}
|
||||
|
||||
{% endblock javascript %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue
Block a user