S
S
Stepan2019-06-28 00:02:42
Django
Stepan, 2019-06-28 00:02:42

How to correctly display the default URL of the language in Django 2.2?

I want to correctly display the list of URLs on the language versions of the page, and I have more than 10 of them. I have
English by default and should always open at the site.com/ URL without /en/ at the end
. I display the list through a loop

{% for language in languages %}
     <a class="col-3" href="/{{ language.code }}/" lang="{{ language.code }}">{{ language.name_local }}</a>
{% endfor %}

For the default language, I get exactly what site.com/en/
requested

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stepan, 2019-06-28
@steopcik

And the solution was right under your nose.

href="{% if language.code == 'en' %}{% else %}/{{ language.code }}{% endif %}/"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question