Задать вопрос

Тел: +7 965 3737 888

473

Просмотров

1

Ответов

Verbose template filter : avoid too many if

<p>This tiny template filter saves you the tedious test "if this variable is set, print this text based on this variable".</p>
<p>'verbose' filter takes one parameter : a string containing '%s' which is a placeholder for the value to test. Check those examples :</p>
<ul><li>
<p>Replace this :</p>
<p>{% if name %}
    Hello {{ name }}, this is a dummy text
{% endif %}</p>
</li>
<li>
<p>By this :</p>
<p>{{ name|verbose:"Hello %s this is a dummy text" }}</p>
</li>
</ul><p>This is also usefull for HTML :</p>
{{ image|verbose:"&lt;img src=\"%s\" /&gt;" }}

Вопрос полезен? Да0/Нет0
file_3240.py(265.0б)
None

Ответы (1):

Ответcarljm:16.06.2008
Ответ полезен? Да0/Нет0

Good stuff, very handy. If used for HTML as in the last example, don't forget to tag on the |safe filter, too.