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
- Serializer factory with Django Rest Framework by julio 5 months, 3 weeks ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 6 months, 1 week ago
- Help text hyperlinks by sa2812 7 months ago
- Stuff by NixonDash 9 months, 1 week ago
- Add custom fields to the built-in Group model by jmoppel 11 months, 2 weeks ago