繁体   English   中英

如何在我的settings.py中的DEBUG变量在Django的模板中可用?

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

无需浏览render_to_response中的字典?

Django已将此内置于django.core.context_processors.debug上下文处理器中。 因此,您只需将其添加到settings.py TEMPLATE_CONTEXT_PROCESSORS设置中。 这将使用请求上下文将debug上下文变量添加到所有视图,并且源代码如下所示:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM