How Do I Render Html Returned From A Filter In Django Template?
I have a md file which needs to be converted into html (for blog website). The filter (markdownify) converts md file into html tags. Now, html tags are shown on the website. How do
Solution 1:
Maybe try
{{ post.body | markdownify | safe }}
.
The safe filter disables any further HTML escaping. Read more about the filter in the Django documentation.
Solution 2:
Adding below code in the settings.py solved the problem. HTML tags are not shown on rendered web page now.
MARKDOWNIFY_WHITELIST_TAGS = {
'a', 'p', 'h1', 'h2', 'h3','h4', 'h5', 'h6', 'h7', 'ul', 'li', 'span', 'img', 'div', 'abbr', 'acronym', 'em', 'blockquote', 'i', 'strong', 'ol', 'b', 'code'
}
Post a Comment for "How Do I Render Html Returned From A Filter In Django Template?"