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. HTML Prettifier by Eloff 6 years, 2 months ago
  2. Revisiting Pygments and Markdown by djypsy 6 years, 8 months ago
  3. prettify html by marchino 7 years ago
  4. Sanitize text field HTML (here from the Dojo Toolkit Editor2 widget) by akaihola 7 years ago
  5. Template Filter: Add indentation by Chuck Harmston 4 years, 7 months ago

Comments

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?)