Skip to content

Make Django Debug Toolbar compatible with Django 1.3 #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def process_response(self, request, response):
self.tag,
smart_unicode(self.debug_toolbars[request].render_toolbar() + self.tag))
if response.get('Content-Length', None):
response['Content-Length'] = len(response.content)
# response.content in Django 1.3 may be an iterator (if it is static)
# copy the value to do not loose it
content = response.content
response['Content-Length'] = len(content)
response.content = content
del self.debug_toolbars[request]
return response
14 changes: 14 additions & 0 deletions debug_toolbar/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
from django.shortcuts import render_to_response
from django.utils import simplejson
from django.utils.hashcompat import sha_constructor
try:
from django.views.decorators.csrf import csrf_exempt
except ImportError:
HAS_CSRF = False
else:
HAS_CSRF = True

class InvalidSQLError(Exception):
def __init__(self, value):
Expand Down Expand Up @@ -98,6 +104,10 @@ def sql_explain(request):
return render_to_response('debug_toolbar/panels/sql_explain.html', context)
raise InvalidSQLError("Only 'select' queries are allowed.")

if HAS_CSRF:
sql_explain = csrf_exempt(sql_explain)


def sql_profile(request):
"""
Returns the output of running the SQL and getting the profiling statistics.
Expand Down Expand Up @@ -141,6 +151,7 @@ def sql_profile(request):
return render_to_response('debug_toolbar/panels/sql_profile.html', context)
raise InvalidSQLError("Only 'select' queries are allowed.")


def template_source(request):
"""
Return the source of a template, syntax-highlighted by Pygments if
Expand Down Expand Up @@ -187,3 +198,6 @@ def template_source(request):
'source': source,
'template_name': template_name
})

if HAS_CSRF:
template_source = csrf_exempt(template_source)