1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import tidy
options = dict(output_xhtml=True,
add_xml_decl=True,
doctype='strict',
indent='auto',
tidy_mark=False,
hide_comments=True,
wrap=100)
class PrettifyMiddleware(object):
"""Prettify middleware"""
def process_response(self, request, response):
if response.headers['Content-Type'].split(';', 1)[0] == 'text/html':
content = response.content
content = str(tidy.parseString(content, **options))
response.content = content
return response
|
More like this
- Prettify HTML5 middleware by runejuhl 1 year, 10 months ago
- HTML Validation Middleware by adamcik 4 years, 3 months ago
- Prettify HTML body contents in HTTP response by n1k0 2 years, 5 months ago
- XhtmlDegraderMiddleware by dmh 5 years, 9 months ago
- Mobilize your Django site by stevena0 4 years, 1 month ago
Comments
This is great, I needed this for a upcoming project. Thanks!
#
I wonder what the performance hit is. Still, this is awesome. Thanks!
#
Has problems with unicode though... messes up all my umlauts.
#
In the latest Django SVN (0.97-pre-SVN-7523) line 16 is just
#
Here's another attempt of achieving the same purpose using BeautifulSoup
#