I would like to include a sass compiler in my Flask application. Is there a generally accepted way of doing this?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Some things have changed since the question was answered in 2013.
You can't have scss installed at the same time as pyscss and expect the pyscss filter to work like in the accepted answer.
I was getting an error that ended in:
You have to remove scss (i.e.
pip uninstall scss
) and be sure that pyscss is installed (i.e.pip install pyscss
).Also note that you will have to set some environment variables in order to get pyscss to work as well:
see the documentation on the pyscss filter for more info: http://webassets.readthedocs.io/en/latest/builtin_filters.html#pyscss
I hope that this save someone else a lot of time because I wasted a whole day on it.
Flask-Assets extension (which uses webassets library) can be used for that. Here's how to configure it to use pyScss compiler (implemented in Python) for SCSS:
And in the template include this:
SCSS files will be compiled in debug mode as well.
pyScss only supports SCSS syntax, but there are other filters (
sass
,scss
andcompass
) which use the original Ruby implementation.Currently, exist a better approach for this issue, the extion Flask-Scss.
You just have to install it:
pip install Flask-Scss
And instanciate a Scss object after configuring the application (probably in your
manage.py
file):By default, the extension will look for your .scss files in
{app.root_dir}/assets/scss
or{app.root_dir}/assets
and will put the generate .css files in{default_static_dir}/css
or{default_static_dir}
.