簡體   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