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
- Set
DEBUG = True
in your settings.py - 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