0

EDIT : I have a python list like this obtained by requesting a mongodb database :

db.coll.find()
> ["Create", "Infra", "Consolidate"]

Is there a way to say in jinja2 template to sort the list in a defined order ? I want an order like this :

["Infra", "Create", "Consolidate"]

I would be happy if something like the following worked. Unfortunately, this is not the case :

{% for item in list|sort("Infra", "Create", "Consolidate") %}
    {{ item }}
{% endfor %}
Jeremy
  • 69
  • 10
  • What's the reasoning for this order? – matszwecja Jun 07 '23 at 08:27
  • A customer-defined constraint :/ It's a process. the first step is the "Infra", then go to the "Create" section et so on. – Jeremy Jun 07 '23 at 08:30
  • 1
    Then just... pass this specific list. `{% for item in ["Infra", "Create", "Consolidate"] %}` – matszwecja Jun 07 '23 at 08:33
  • Note that you pass a tuple to the sort function, not a list. Tuples are immutable. – Itération 122442 Jun 07 '23 at 08:53
  • I notice there is a lack of informations. The orignal list ["Create", "Infra", "Consolidate"] is obtained by requesting a mongodb database : db.coll.find(). I just editing the original message. – Jeremy Jun 07 '23 at 09:24
  • I found my answer with custom sort based on this thread : https://stackoverflow.com/a/75643901/11758711 – Jeremy Jun 07 '23 at 10:21

0 Answers0