Answer the question
In order to leave comments, you need to log in
How to output unshuffled dict in django template?
Hello. I'm trying to display a list in a template, in quite the usual way, in the context I declared a list,
def menu_context_processor(request):
main_menu_list = {
'Новости':'news',
'Статьи':'articles',
'О компании':'about',
'Каталог':'catalog',
'Контакты':'contacts'
}
return {'main_menu_list': main_menu_list.items()}
{% for menu_key, menu_val in main_menu_list %}
<li><a href="{% url menu_val %}">{{ menu_key|nbsp }}</a></li>
{% endfor %}
Answer the question
In order to leave comments, you need to log in
Don't use a dictionary? A dictionary is a hash table, it doesn't store the sequence. Use a tuple, list, or ordered dictionary.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question