I organized the templates in my Django project so that each page of the site contains a “shared” LESS file, and each page can also specify a different LESS file that contains styles related to the page.
The problem is that I need a LESS file for a specific page in order to be able to refer to variables in a "shared" LESS file. The easiest way to do this, I thought, was to simply move the variable declarations to a separate file that both LESS files could @import.
However, Django applications use separate directories to store their static files. As a result, the file system looks something like this:
- common
- static
- css
- definitions.less
- common.less
- other
- static
- css
- other.lessBoth common.lessand other.lessmust be imported definitions.less. In the case, common.lessit is as simple as:
@import "definitions.less";
Here's how the LESS files are actually included on the page, just in case that helps:
{% load compress %}
{% load static %}
{% compress css %}
<link href="{% static "css/common.less" %}"
rel="stylesheet" type="text/less">
{% endcompress %}
What would be the easiest way to ensure that common variables are defined for both LESS files? I want to avoid merging LESS files for several reasons:
- It removes the benefits of a weakened connection (the ability to deactivate the application without any side effects on the rest of the site).
- The extra data retrieved for one page is increased because all styles for all applications must be retrieved.
source
share