Login

Tag "indentation"

Snippet List

Prettify HTML body contents in HTTP response

This is an enhancement of snippet [#172](http://djangosnippets.org/snippets/172/). Here I use [BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) — far more easier to install through pip in a virtualenv, and possibly a bit more maintained — to format and properly indent the rendered HTML from templates. I also added a check to only tidy contents in a `DEBUG=True` environment, regarding high impact on performance while doing so in production. Last, it's compatible with Django 1.2.x.

  • templates
  • format
  • html
  • tidy
  • syntax
  • output
  • prettify
  • formatting
  • indentation
  • readability
Read More

Template Filter: Add indentation

Template filter to add the given number of tabs to the beginning of each line. Useful for keeping markup pretty, plays well with Markdown. Usage: {{ content|indent:"2" }} {{ content|markdown|indent:"2" }}

  • filter
  • markup
  • pretty
  • indent
  • indentation
Read More

2 snippets posted so far.