문제

I have in template and variables s1, s2, s3

<input type="text" value="{% if s1 %}{{s1}}{% endif %}{% if s2 %}{{s2}}{% endif %}{% if s3 %}{{s3}}{% endif %}" />

is there better way of doing

{% if s1 %}{{s1}}{% endif %}{% if s2 %}{{s2}}{% endif %}{% if s3 %}{{s3}}{% endif %}

?

도움이 되었습니까?

해결책

Use default filter:

If value evaluates to False, uses the given default. Otherwise, uses the value.

{{ s1|default:"" }}

다른 팁

You could use the elif tag.

{% if s1 %}{{s1}}{% elif s2 %}{{s2}}{% elif s3 %}{{s3}}{% endif %}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top