Prettify HTML body contents in HTTP response

 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

  1. urlize HTML by maguspk 3 years ago
  2. Sanitize text field HTML (here from the Dojo Toolkit Editor2 widget) by akaihola 6 years, 2 months ago
  3. HTML Prettifier by Eloff 5 years, 4 months ago
  4. Revisiting Pygments and Markdown by djypsy 5 years, 10 months ago
  5. Prettify HTML5 middleware by runejuhl 1 year, 11 months ago

Comments

n1k0 (on November 30, 2010):

Okay, now with the "More like this" list updated, I realize this is a silly duplicate of #570. Doh!

#

cricogik (on December 7, 2010):

It's ok n1k0. Yours version of PrettifyMiddleware is better because #570 don't check DEBUG status.

#

(Forgotten your password?)