Search code examples
djangotemplatesbolditalictemplatetag

Django Template tag to allow bold and italic elements


Django has a template tag that allows you to remove certain html tags from being displayed in stored data.

The django documentation gives an example. Any b or span tags are removed. https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#removetags

{{ value|removetags:"b span"|safe }}

However, I'm wondering if there is a good way to do the inverse. For example, blacklist all tags except for tags specified. In my case, I just want to allow bold and italic tags.


Solution

  • Write your own template tag using bleach.