jinja2

Difference of writing jinja2 macro in one line V.S. writing macro in multiple lines?

Difference of writing jinja2 macro in one line V.S. writing macro in multiple lines? Question: I have next jinja2 template: cfg.jinja2: {% macro cfg() %}ABC{% endmacro %} {% macro cfg2() %} ABC {% endmacro %} resource: {{ cfg()|indent(4) }} {{ cfg2()|indent(4) }} And, next python file: test.py: import os from jinja2 import Environment, FileSystemLoader path_dir …

Total answers: 1

how to iterate over one field in jinja2

how to iterate over one field in jinja2 Question: I have a database that looks like this: Name | Phone_no | Country | Zipcode ———————————– Foo | 12345 | USA | 92121 Bar | 65745 | UK | 15409 Arm | 77745 | UAE | 88844 Mac | 88845 | USA | 66623 Dox | …

Total answers: 1

How can the default list of email addresses be rendered from a variable in Airflow?

How can the default list of email addresses be rendered from a variable in Airflow? Question: I have a lot of Airflow DAGs and I’d like to automatically send email notifications to the same list of recipients (stored in an Airflow variable) on any task failure, so I’m using the following default operator configuration defined …

Total answers: 2

How to retrieve results that contain JSON from SQLite for use in a jinja template?

How to retrieve results that contain JSON from SQLite for use in a jinja template? Question: I have a SQLite DB that I query like this: products = cursor.execute( Select Item,EntryDate,json_group_array(json_object(‘color’,P.option)) as colorarray ….. ).fetchall() The results of products can look like this [(‘dress’, ‘2022-12-27 00:00:00’, ‘[{"color":"blue"},{"color":"green"}]’)] In my jinja template I try to loop …

Total answers: 1

How do I get FastAPI to do SSR for Vue 3?

How do I get FastAPI to do SSR for Vue 3? Question: According to this documentation for Vue’s SSR, it is possible to use node.js to render an app and return it using an express server. Is is possible to do the same with FastAPI? Or is using Jinja2 templates or SPA the only solution? …

Total answers: 1

How to sort a list of dictionaries alphabetically in Jinja2

How to sort a list of dictionaries alphabetically in Jinja2 Question: My sample list of dictionaries is shown below: mydata = [{‘data’: [27, 3, 30, None, None], ‘name’: ‘S1’}, {‘data’: [57.33, 6.37, 63.7, None, None], ‘name’: ‘A2’}, {‘data’: [2349.62, 261.09, 2610.71, 0, 0], ‘name’: ‘Total’}] I want to sort the whole list of dictionaries alphabetically …

Total answers: 1

Replacing a double space with a break tag in flask

Replacing a double space with a break tag in flask Question: I have a database with each row being a particular event. Every event has an associated information column. In flask I’m trying to replace double spaces in the information string with a <br> tag for the html document. However when I do it the …

Total answers: 1

Iterate over json string items in jinja2

Iterate over json string items in jinja2 Question: Hi I need to send data in string format to my jinja templates, and the render them. The only way I found is to format my data as JSON and send it as a string to the renderer. But I donĀ“t know how to use it in …

Total answers: 1

Nested Dict to Table in Jinja2

Nested Dict to Table in Jinja2 Question: I am scratching my head trying to correctly format a table from a nested dict in Jinja2, but having no luck. The dict is something like this: dict = { key_1: {a: 1, b: 2, c: 3}, key_2: {a: 11, b: 12, c: 13}, } And I want …

Total answers: 2