[英]How do I obtain django default settings values NOT defined in my settings.py file?
[英]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.