Skip to content

Instantly share code, notes, and snippets.

@mtigas
Created April 28, 2011 20:50
Show Gist options
  • Save mtigas/947307 to your computer and use it in GitHub Desktop.
Save mtigas/947307 to your computer and use it in GitHub Desktop.
Django SpacelessHtmlResponse
from django.utils.html import strip_spaces_between_tags
class SpacelessHtmlResponse(object):
"""
Equivalent to running {% spaceless %} template tag against a full HTML response.
"""
def process_response(self, request, response):
if response.get("Content-Type", "").startswith("text/html"):
response.content = strip_spaces_between_tags(response.content.strip())
return response
@mtigas
Copy link
Author

mtigas commented Apr 28, 2011

inb4 “this is a terrible idea”

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