Login

HTML Prettifier

Author:
Eloff
Posted:
January 30, 2008
Language:
Python
Version:
.96
Tags:
html pretty prettify ugly indented
Score:
4 (after 4 ratings)

Tired of scrolling through hundreds of lines of code where the indentation is maddening?

Here's a middleware class that prettifys your html markup so it's nice and consistently indented. Intended only for debugging, and I add it to the middleware stack conditionally on TEMPLATE_DEBUG. Requires BeautifulSoup.

1
2
3
4
5
6
7
8
from BeautifulSoup import BeautifulSoup

class Prettify(object):
    def process_response(self, request, response):
        if response.has_header('Content-Type') and response['Content-Type'].startswith('text/html'):
            response.content = BeautifulSoup(response.content).prettify()
        
        return response

More like this

  1. Prettify HTML body contents in HTTP response by n1k0 4 years, 8 months ago
  2. prettify html by marchino 8 years, 3 months ago
  3. Prettify HTML5 middleware by runejuhl 4 years ago
  4. HTML Validation Middleware by adamcik 6 years, 5 months ago
  5. Template tag for stripping blank lines by akaihola 7 years, 6 months ago

Comments

Please login first before commenting.