Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Override CSS when Debug=True

In order to avoid confusion between my production and development instance (where DEBUG = True), I’d like to override the CSS of my bootstrap Navbar in development (only) to show up e.g. in red instead of blue.

What is the most elegant way to accomplish this?

I can override get_context_data() everywhere to include my settings.DEBUG, or inherit from newly generated base classes, but that doesn’t seem very DRY.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can leverage django debug context processor, which allows you to use debug template variable in every template.

This value is equal to settings.DEBUG so you can use it to override you css E.g.

{% if debug %}
    <style>
        .nav { background-color: red }
    </style>
{% endif %}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading