问题描述:

Say var is a variable passed with return from a view to a template. Could you please give me a simple example to understand the difference between rendering {{ var }} on the one hand and {{ var|safe }} on the other? I was not able to fully understand what is going on in the documentation: 1, 2. In which case |safe protects me? Thank you very much!

网友答案:

The safe template filter allows html tags and entities in the content of var. Without it, your html will be escaped so you'll see things like

<div> &nbsp;

etc on your page.

网友答案:

If var has html elements then the safe template filter will render it.

For example:

If var is hi

var|safe will be rendered hi var will be displayed <b>hi</b>

网友答案:

Simply saying django's safe method in template doesn't render any html tags in template

相关阅读:
Top