How to check the TEMPLATE_DEBUG flag in a django template?

前端 未结 6 740
既然无缘
既然无缘 2020-12-04 15:31

Do you know if it is possible to know in a django template if the TEMPLATE_DEBUG flag is set?

I would like to disable my google analytics script when I am running my

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 15:51

    Assuming you haven't set TEMPLATE_CONTEXT_PROCESSORS to some other value in settings.py, Django will automatically load the debug context preprocessor (as noted here). This means that you will have access to a variable called debug in your templates if settings.DEBUG is true and your local machine's IP address (which can simply be 127.0.0.1) is set in the variable settings.INTERNAL_IPS (which is described here). settings.INTERNAL_IPS is a tuple or list of IP addresses that Django should recognize as "internal".

提交回复
热议问题