Created
November 18, 2017 10:37
-
-
Save marcus-crane/01ad3aeb465130bda57999eaba40842d to your computer and use it in GitHub Desktop.
Django 2.0 HTML Prettify Middleware
This file contains hidden or 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 html5print import HTMLBeautifier | |
class PrettifyMiddleware: | |
"""Prettify HTML for anyone interested in reading the source of this site.""" | |
def __init__(self, get_response): | |
self.get_response = get_response | |
def __call__(self, request): | |
response = self.get_response(request) | |
if response['Content-Type'].split(';')[0] == 'text/html': | |
response.content = HTMLBeautifier.beautify(response.content, 2) | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment