[英]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.