Login

Tag "escape"

Snippet List

htmlentities

The built-in escape filter only works with certain characters. It works great in environments where you can declare your charset (UTF-8). However, not everything can handle anything outside of the ASCII charset. This replaces all non-ASCII characters with their encoded value as `®` for ®, for example.

  • escape
  • htmlentities
  • ascii
Read More

keeptags: strip all HTML tags from output except a specified list of elements

Django has several filters designed to sanitize HTML output, but they're either too broad (striptags, escape) or too narrow (removetags) to use when you want to allow a specified set of HTML tags in your output. Thus keeptags was born. Some of the code is essentially ripped from the Django removetags function. It's not perfect--for example, it doesn't touch attributes inside elements at all--but otherwise it works well.

  • filter
  • html
  • escape
Read More

3 snippets posted so far.