Created
April 28, 2011 20:50
-
-
Save mtigas/947307 to your computer and use it in GitHub Desktop.
Django SpacelessHtmlResponse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
inb4 “this is a terrible idea”