문제

I want to print something on the basis of the current language code. For that I did something like this:

{% if request.LANGUAGE_CODE == en %}
    <h1>English</h1>
{% endif %}

But this if condition does not compare the current language code. But if I print this {{request.LANGUAGE_CODE}} on the same page then it will print en as language code, but my if condition is not working and I don't know why ??

도움이 되었습니까?

해결책

LANGUAGE_CODE is a string, so you just need to enquote your comparison value like this:

{% if request.LANGUAGE_CODE == 'en' %}
    <h1>English</h1>
{% endif %}

check also the ifequal tag

{% ifequal request.LANGUAGE_CODE 'en' %}
    ...
{% endifequal %}

a bit more: the if and ifequal on strings are case sensitive, so you may want to be sure you're matching the correct case (maybe applying the |lower filter to both arguments)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top