Will & Skill Developers

Will & Skill Developers


Thoughts, snippets and ideas from the team at Will & Skill AB, Stockholm.

Faisal Mahmud
Author

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

Share


DEBUG mode in Django templates

Faisal MahmudFaisal Mahmud

A lot of people add their own context processor but there is a better and safer way to do this in Django.

The necessary steps

  1. Set DEBUG = True in your settings.py
  2. Add your current IP to INTERNAL_IPS in your settings.py

Your settings.py file

# settings.py

# Set DEBUG = True
DEBUG = True

# Add the IP of your computer
INTERNAL_IPS = ["127.0.0.1"]

And in your template

{% if debug %}
    <script src="{{ APP_URL }}js/app.js?_={{ RELEASE_TAG }}"></script>
{% else %}
    <script src="{{ APP_URL }}js/app.min.js?_={{ RELEASE_TAG }}"></script>
{% endif %}

Why is this better than creating a custom context processor?

This will make sure to serve only the non-debug parts of your site if you accidentally were to push to your production environment with DEBUG = True.

You can think of it as an extra safety measure so that your site/app does not leak sensitive data!

Read more in the docs

Faisal Mahmud
Author

Faisal Mahmud

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

Comments