Instantly share code, notes, and snippets.

What would you like to do?
Example on how to debug Tastypie using Django Debug Toolbar
def html_decorator(func):
This decorator wraps the output in html.
def _decorated(*args, **kwargs):
response = func(*args, **kwargs)
wrapped = ("<html><body>",
return HttpResponse(wrapped)
return _decorated
def debug(request):
Debug endpoint that uses the html_decorator,
path = request.META.get("PATH_INFO")
api_url = path.replace("debug/", "")
view = urlresolvers.resolve(api_url)
accept = request.META.get("HTTP_ACCEPT")
accept += ",application/json"
request.META["HTTP_ACCEPT"] = accept
res = view.func(request, **view.kwargs)
return HttpResponse(res._container)
# And finally attach debug to urls (if settings is on)
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^debug/', debug),
Lets say your original endpoint is this:
You use the following url the debug it

This comment has been minimized.

nokome commented Sep 21, 2015

@marteinn: just what I was looking for, thanks!


This comment has been minimized.

olifante commented Oct 27, 2015

@marteinn: also worked for me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment