5

I'm using django-compressor + LESS.

I have a problem with relative @import inside .less file and relative url(../image.png) in included .less file.

I will explain. I have next folder structure:

common/  # Django app with some common stuff, e.g. common button styles
   static/
     common/
       less/buttons.less
       img/icon.png
blog/
  static/
    blog/
      less/blog_buttons.less

Inside buttons.less I have mixin for button:

.button() {
    color: white;
    padding: 4px 10px;
    background: gray url(../img/icon.png) no-repeat 0 0;
}

Inside blog_buttons.less I use this mixin:

@import "../../../../common/static/common/less/buttons";

.blog_button {
    .button;
    background-color: orange;
}

And here is the problem:

when django-compress pre-compiles my blog_buttons.less - button background points to /static/blog/img/icon.png (404 Not Found). But it should point to /static/common/img/icon.png

Am I doing something wrong? (I think that it should be a kind of very common situation)

Zulu
  • 8,765
  • 9
  • 49
  • 56
Rost
  • 3,602
  • 2
  • 21
  • 21

2 Answers2

0

If your static paths are configured correctly, you should be able to treat both common/static and blog/static as if they were the same folder. Your import statement should rather look like this:

@import "../../common/less/buttons";
Martin Blech
  • 13,135
  • 6
  • 31
  • 35
0

My answer to this question is probably relevant. You may also want to add the '--relative-url' argument to lessc https://stackoverflow.com/a/25929152/559629.

Community
  • 1
  • 1
wjin
  • 954
  • 1
  • 8
  • 13