Tsubasa ,

  • 5309


  • 0




資料/Django and SCSS.





  SCSS 教學/官方 Guide:Link (全英文注意)


Integration with Django

SASS can be easily included into your Django project by using Django Compressor. Firstly, you must install SASS, which requires Ruby, by using the command:

gem install SASS

Next, you must follow the steps to get Django Compressor up and running. Finally, you must add the following pre-compiler to your projects settings file:

    ('text/scss', 'sass --scss {infile} {outfile}'),

Now you are ready to use SASS in your project! just include the compress template tag around your stylesheet links:

{% load compress %}
{% load staticfiles %}

{% compress css %}
    <link rel="stylesheet" type="text/scss" href="{% static 'styles.scss' %}" />
{% endcompress %}

And your SASS will be compiled into CSS on the fly!

Using Compass

Compass is a SASS library that includes blueprints and mixins that make writing stylesheets with SASS even easier. The Compass docs explain all of the mixins that are included and some examples of how you can use them. Integrating Compass with your SASS requires a little bit of extra work when using Django Compressor. Firstly, make sure you install compass with the following command:

gem install compass

Next, you will need to make sure that if you have previously installed SASS, you delete it and use the version that comes with Compass. Compass doesn't always play nicely with the newest version of SASS, so it is important that you take this step. All you have to do from here is modify your COMPRESS_PRECOMPILERS in your project settings. Replace the previous pre-compiler with the following:

('text/scss', 'sass --scss --compass {infile} {outfile}')

That's it, you are now ready to use SASS with the added power of Compass in your Django project!