2011-01-26 52 views

回答

3

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 
相關問題