{"id":4509,"library":"django-libsass","title":"django-libsass","description":"django-libsass is a Django Compressor filter that compiles Sass (SCSS) files using the `libsass-python` binding of LibSass. It integrates seamlessly into Django's static files and compressor pipeline, allowing developers to write Sass without external build tools. The current version is 0.9, and it receives infrequent but active maintenance updates for Django compatibility.","status":"active","version":"0.9","language":"en","source_language":"en","source_url":"https://github.com/torchbox/django-libsass","tags":["django","sass","scss","libsass","css preprocessor","django-compressor"],"install":[{"cmd":"pip install django-libsass django-compressor libsass","lang":"bash","label":"Install with dependencies"}],"dependencies":[{"reason":"django-libsass functions as a filter for django-compressor to process Sass files.","package":"django-compressor"},{"reason":"This package provides the Python bindings for LibSass, the underlying C/C++ Sass engine used for compilation.","package":"libsass"}],"imports":[{"note":"Used to configure django-compressor to use SassCompiler as a precompiler for 'text/x-scss' content types.","symbol":"SassCompiler","correct":"from django_libsass import SassCompiler"}],"quickstart":{"code":"import os\n\n# settings.py\n\nINSTALLED_APPS = [\n    # ...\n    'compressor',\n    'django.contrib.staticfiles',\n    # 'your_app' (where your .scss files live in static/your_app/)\n]\n\nSTATIC_URL = '/static/'\nSTATICFILES_FINDERS = (\n    'django.contrib.staticfiles.finders.FileSystemFinder',\n    'django.contrib.staticfiles.finders.AppDirectoriesFinder',\n    'compressor.finders.CompressorFinder',\n)\n\nCOMPRESS_PRECOMPILERS = (\n    ('text/x-scss', 'django_libsass.SassCompiler'),\n)\n\nCOMPRESS_ENABLED = True # Set to False in production for offline compression\nCOMPRESS_OFFLINE = False # Set to True in production for offline compression\n\n# Optional: Configure additional libsass settings\n# LIBSASS_OUTPUT_STYLE = 'compressed'\n# LIBSASS_PRECISION = 8 # Recommended for frameworks like Bootstrap\n# LIBSASS_ADDITIONAL_INCLUDE_PATHS = [\n#     os.path.join(BASE_DIR, 'path/to/extra/sass/includes'),\n# ]\n\n# templates/base.html\n# ...\n# {% load static %}\n# {% load compress %}\n# ...\n# {% compress css %}\n#   <link rel=\"stylesheet\" type=\"text/x-scss\" href=\"{% static 'your_app/css/main.scss' %}\">\n# {% endcompress %}\n# ...\n\n# your_app/static/your_app/css/main.scss\n// Example SCSS content\n$primary-color: #337ab7;\n\nbody {\n  background-color: lighten($primary-color, 40%);\n  a {\n    color: $primary-color;\n    &:hover {\n      text-decoration: underline;\n    }\n  }\n}","lang":"python","description":"To quickly integrate `django-libsass`, first ensure `django-compressor` is set up. Add `compressor` to `INSTALLED_APPS` and `compressor.finders.CompressorFinder` to `STATICFILES_FINDERS`. Then, configure `COMPRESS_PRECOMPILERS` in your `settings.py` to use `django_libsass.SassCompiler` for `text/x-scss` files. Finally, in your Django templates, load the `compress` and `static` tags and wrap your SCSS `link` tag within `{% compress css %}` and `{% endcompress %}` blocks, specifying `type=\"text/x-scss\"`."},"warnings":[{"fix":"Be aware of potential future limitations. For new projects, evaluate alternatives like `django-sass-processor` with Dart Sass if cutting-edge Sass features are required.","message":"The underlying LibSass library is officially deprecated by the Sass team in favor of Dart Sass. While `libsass-python` and `django-libsass` will continue to receive maintenance updates, no new features or compatibility with future Sass language updates are planned. Consider this for long-term project planning.","severity":"deprecated","affected_versions":"All versions"},{"fix":"Always use the latest stable version of `django-libsass` to ensure compatibility with your Django and `django-compressor` versions. Check release notes for specific version requirements.","message":"Older versions of `django-libsass` may not be compatible with newer Django or `django-compressor` versions. For example, v0.6 fixed compatibility with `django-compressor` 1.6, and v0.9 added support for Django 3.1/3.2.","severity":"breaking","affected_versions":"< 0.9"},{"fix":"Set `LIBSASS_PRECISION = 8` (or higher if needed) in your `settings.py` when using such frameworks.","message":"When using CSS frameworks like Bootstrap that rely on high precision in Sass calculations, the default `LIBSASS_PRECISION` (5) might be insufficient, leading to layout issues. Bootstrap, for instance, typically requires a precision of 8.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Organize your SCSS files so that `@import` paths are relative to a recognized static files directory or an entry in `LIBSASS_ADDITIONAL_INCLUDE_PATHS`. Avoid `../` in `@import` statements.","message":"While `django-libsass` attempts to resolve `@import` paths using `STATICFILES_FINDERS`, explicitly traversing up the directory tree with `../` in `@import` statements might not work reliably and is discouraged by some related tools.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure only `libsass` (via `pip install libsass`) is installed as your Sass compiler if you are using `django-libsass`. Uninstall other conflicting Sass-related Python packages.","message":"Installing multiple Python packages that provide a `sass` module (e.g., `libsass` and other Sass processors) can lead to namespace conflicts and errors like `module 'object' has no attribute 'compile'`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}