[Fixed]-How to use Sass in Django and versioning CSS and JS assets for cache busting

1๐Ÿ‘

โœ…

I use django_assets for this. For my CSS and SASS files, I use an assets.py file that looks like this:

css_bundle = Bundle(
    'scss/main.scss',
    depends=('scss/**/*.scss',),
    filters='pyscss,cssmin',
    output='compiled/main.min.css'
)

register('css_bundle', css_bundle)

Which I can then include in my templates like this:

{% assets "css_bundle" %}
  <link rel="stylesheet" href="{{ ASSET_URL }}"/>
{% endassets %}

Cache busting is built right in, and you can do something similar for JS files.

๐Ÿ‘ค2ps

Leave a comment