Repository: jazzband/django-debug-toolbar

Issue:
Pass context_instance to the toolbar templates
It would be great if the toolbar templates had access to template context processors.

Passing "context_instance=RequestContext(self.request)" to the render_to_string call in "loader.py - render_toolbar()" does the trick.

It makes it easier for anyone who wants to overload the templates and wants for example to change the location of the toolbar media or change how they are served.



Discussion:
How does having the request in the context make it easier to overload templates? Can you provide a specific use case?

Shouldn't we just switch from `render_to_response` to `render`?


Resolving patch:
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py
--- a/debug_toolbar/middleware.py
+++ b/debug_toolbar/middleware.py
@@ -9,7 +9,7 @@
 
 from django.conf import settings
 from django.http import HttpResponseRedirect
-from django.shortcuts import render_to_response
+from django.shortcuts import render
 from django.utils.encoding import force_text
 from django.utils.importlib import import_module
 from django.utils import six
@@ -125,7 +125,8 @@ def process_response(self, request, response):
             redirect_to = response.get('Location', None)
             if redirect_to:
                 cookies = response.cookies
-                response = render_to_response(
+                response = render(
+                    request,
                     'debug_toolbar/redirect.html',
                     {'redirect_to': redirect_to}
                 )
diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py
--- a/debug_toolbar/views.py
+++ b/debug_toolbar/views.py
@@ -7,7 +7,7 @@
 from __future__ import unicode_literals
 
 from django.http import HttpResponseBadRequest
-from django.shortcuts import render_to_response
+from django.shortcuts import render
 from django.views.decorators.csrf import csrf_exempt
 
 from debug_toolbar.forms import SQLSelectForm
@@ -33,7 +33,7 @@ def sql_select(request):
             'headers': headers,
             'alias': form.cleaned_data['alias'],
         }
-        return render_to_response('debug_toolbar/panels/sql_select.html', context)
+        return render(request, 'debug_toolbar/panels/sql_select.html', context)
     return HttpResponseBadRequest('Form errors')
 
 
@@ -70,7 +70,7 @@ def sql_explain(request):
             'headers': headers,
             'alias': form.cleaned_data['alias'],
         }
-        return render_to_response('debug_toolbar/panels/sql_explain.html', context)
+        return render(request, 'debug_toolbar/panels/sql_explain.html', context)
     return HttpResponseBadRequest('Form errors')
 
 
@@ -105,7 +105,7 @@ def sql_profile(request):
             'headers': headers,
             'alias': form.cleaned_data['alias'],
         }
-        return render_to_response('debug_toolbar/panels/sql_profile.html', context)
+        return render(request, 'debug_toolbar/panels/sql_profile.html', context)
     return HttpResponseBadRequest('Form errors')
 
 
@@ -147,7 +147,7 @@ def template_source(request):
     except ImportError:
         pass
 
-    return render_to_response('debug_toolbar/panels/template_source.html', {
+    return render(request, 'debug_toolbar/panels/template_source.html', {
         'source': source,
         'template_name': template_name
     })


Test patch: