1 2 3 4 5 6 7 8 9 10 11 | import settings
from BeautifulSoup import BeautifulSoup
class PrettifyMiddleware(object):
"""HTML code prettification middleware."""
def process_response(self, request, response):
if settings.DEBUG and response['Content-Type'].split(';', 1)[0] == 'text/html':
response.content = BeautifulSoup(response.content).prettify()
return response
|
More like this
- urlize HTML by maguspk 3 years ago
- Sanitize text field HTML (here from the Dojo Toolkit Editor2 widget) by akaihola 6 years, 2 months ago
- HTML Prettifier by Eloff 5 years, 4 months ago
- Revisiting Pygments and Markdown by djypsy 5 years, 10 months ago
- Prettify HTML5 middleware by runejuhl 1 year, 11 months ago
Comments
Okay, now with the "More like this" list updated, I realize this is a silly duplicate of #570. Doh!
#
It's ok n1k0. Yours version of PrettifyMiddleware is better because #570 don't check DEBUG status.
#