开发者

How do I make the DEBUG variable in my settings.py available in my templates in Django?

开发者 https://www.devze.com 2023-02-07 10:32 出处:网络
Without having to go through the dictionary in render_to_respon开发者_运维问答se?Django has this built into the django.core.context_processors.debug context processor.So you just need to add that to y

Without having to go through the dictionary in render_to_respon开发者_运维问答se?


Django has this built into the django.core.context_processors.debug context processor. So you just need to add that to your TEMPLATE_CONTEXT_PROCESSORS setting in your settings.py. This adds the debug context variable to all views using request context, and the source looks like this:

def debug(request):
    "Returns context variables helpful for debugging."
    context_extras = {}
    if settings.DEBUG and request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
        context_extras['debug'] = True
        from django.db import connection
        context_extras['sql_queries'] = connection.queries
    return context_extras
0

精彩评论

暂无评论...
验证码 换一张
取 消