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 %}
6
  • What's the reasoning for this order? Commented Jun 7, 2023 at 8:27
  • A customer-defined constraint :/ It's a process. the first step is the "Infra", then go to the "Create" section et so on. Commented Jun 7, 2023 at 8:30
  • 1
    Then just... pass this specific list. {% for item in ["Infra", "Create", "Consolidate"] %} Commented Jun 7, 2023 at 8:33
  • Note that you pass a tuple to the sort function, not a list. Tuples are immutable. Commented Jun 7, 2023 at 8: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. Commented Jun 7, 2023 at 9:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.