Source

garter / docs / content / lesscss.markdown

<h1><a href="">LessCSS Support</a></h1>

If you use LessCSS to stay sane while writing CSS, you probably know it can be a pain to run lessc --watch static/style.less every time you want to work on your styles. It gets even worse when you have more than one .less file.

Garter provides a function that will automatically re-render .less files into CSS before each request if they've changed.

You can activate it by calling the lesscss function with your Flask app as a parameter:

from garter.lesscss import lesscss
lesscss(app)

This will watch your app's static media directory and automatically render .less files into .css files in the same (sub)directory.

When you deploy your app you might not want to accept the overhead of checking the modification time of your .less and .css files on each request. A simple way to avoid this is wrapping the lesscss call in an if statement:

if app.debug:
    from garter.lesscss import lesscss
    lesscss(app)

If you do this you'll be responsible for rendering the .less files into CSS when you deploy in non-debug mode to your production server.