Skip to content

Commit

Permalink
Tip for usage with default filter II.
Browse files Browse the repository at this point in the history
Hi James!
As you state in the README, "rendered" attribute on Markup is of SafeText type. If "default" filter is applied to "rendered", output for browser is escaped - it displays HTML value, not interpret it as HTML. I've discovered that if I finish filter chain with "safe", HTML is not escaped.

Please keep in mind that I'm Django newbie and I'm unsure whether it's a bug or my misunderstanding of Django.
  • Loading branch information
liborjelinek committed Oct 11, 2016
1 parent 6557dc5 commit 4e5c045
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -186,9 +186,9 @@ assignment to ``a.body_markup_type`` is equivalent to assignment to
{{ a.body|default:"<missing body>" }}
That's because ``body`` is regular non-``None`` MarkupField instance. To let ``default`` or ``default_if_none`` filters to work evaluate ``rendered`` MarkupField attribute instead::
That's because ``body`` is regular non-``None`` MarkupField instance. To let ``default`` or ``default_if_none`` filters to work evaluate ``rendered`` MarkupField attribute instead. To prevent escaping HTML for the case ``rendered`` is truethy, finish chain with ``safe`` filter::
{{ a.body.rendered|default:"<missing body>" }}
{{ a.body.rendered|default:"<missing body>"|safe }}

.. note::
a.body.rendered is only updated when a.save() is called
Expand Down

0 comments on commit 4e5c045

Please sign in to comment.