Mettre en forme une date
Supposons qu'un appel d'API vous renvoie une date au format 20230730T1028, stockée dans la variable departure_api. Vous pouvez utiliser le filtre to_date (l'un de nos filtres Jinja personnalisés) pour la convertir en objet Python datetime, puis afficher la date au format de votre choix avec la méthode strftime des objets datetime.
Python
# departure_api contains the following value "20230730T1028"
# departure_api is converted into a datetime object
{% set departure=departure_api | to_date %}
# departure is formated according to the following format "%H:%M - %d/%m/%Y"
{% set departure=departure.strftime("%H:%M - %d/%m/%Y") %}
# After the execution of the block the variable departure contains
# the following value "10:28 - 30/07/2023"