I have a production and local DJANGO development environment. To push things to production we have a deployer which minifies and gzips all CSS and JS files.
To serve them on production I need to call them like
<link rel="stylesheet" href="{{ STATIC_URL }}css/filename.min.css.gz">
However on development I want the normal css file served (that way I don't have to re-minify and gzip each time I save) with:
<link rel="stylesheet" href="{{ STATIC_URL }}css/filename.css">
Is there any way to achieve and automatize this behaviour by adding something to the deployer?, is there some other work-around (I could get rid of the .min extension if it's possible to add the .gz in a clean way?
I want to note the I know I could implement some html-parser which adds it on each deploy but I'm looking for a neat and django oriented solution.
I like the @Nursultan idea. To enforce this you could code a context processor like this:
# On yourapp.context_processor.py
from django.conf import settings
def debug_set(request):
return {'debug_set': settings.DEBUG}
# On your settings.py
TEMPLATE_CONTEXT_PROCESSORS = (
.
.
.
'yourapp.context_processors.debug_set',
)
# On your templates
{% if debug_set %}
<link rel="stylesheet" href="{{ STATIC_URL }}css/filename.css">
{% else %}
<link rel="stylesheet" href="{{ STATIC_URL }}css/filename.min.css.gz">
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With