Django provides template filters that implement the following markup languages:
- textile – implements Textile – requires PyTextile
- markdown – implements Markdown – requires Python-markdown
- restructuredtext – implements reST (reStructured Text) – requires doc-utils
In each case, the filter expects formatted markup as a string and returns a string representing the marked-up text. For example, the textile filter converts text that is marked-up in Textile format to HTML.
To activate these filters, add 'django.contrib.markup' to your INSTALLED_APPS setting. Once you’ve done that, use {% load markup %} in a template, and you’ll have access to these filters. For more documentation, read the source code in django/contrib/markup/templatetags/markup.py.
Warning
The output of markup filters is marked “safe” and will not be escaped when rendered in a template. Always be careful to sanitize your inputs and make sure you are not leaving yourself vulnerable to cross-site scripting or other types of attacks.
When using the restructuredtext markup filter you can define a RESTRUCTUREDTEXT_FILTER_SETTINGS in your django settings to override the default writer settings. See the restructuredtext writer settings for details on what these settings are.
The Python Markdown library supports options named “safe_mode” and “enable_attributes”. Both relate to the security of the output. To enable both options in tandem, the markdown filter supports the “safe” argument.
{{ markdown_content_var|markdown:”safe” }}
Warning
Versions of the Python-Markdown library prior to 2.1 do not support the optional disabling of attributes and by default they will be included in any output from the markdown filter - a warning is issued if this is the case.
May 10, 2012