Why does the Jinja2 template is throwing jinja2.exceptions.TemplateNotFound error even though file is there?

Advertisements I’m struggling with the Jinja2 templating system. Even though the error path is pointing exactly to the .jinja2 file it is throwing template not found error. Here is the current structure of folder. ❯ tree . ├── generate_template.py └── templates ├── kustomization.jinja2 ├── pwa.jinja2 └── shopware.jinja2 Here is content of generate_template.py import jinja2 import… Read More Why does the Jinja2 template is throwing jinja2.exceptions.TemplateNotFound error even though file is there?

Why does using set in a jinja template not persistently change the value from the perspective of later content?

Advertisements I’m trying to use the jinja2 moudle… It’s working differently than I expected. The value of the variable has_swimming should change within the for loop, but it resets to the initial value. The code below is intended to perform a function that finds instances where the hobby is SWIMMING in a list of dictionaries,… Read More Why does using set in a jinja template not persistently change the value from the perspective of later content?

Airflow RedshiftToS3Operator: using parameters

Advertisements I’m tryng to pass parameters into my query sql using parameters parameter into a RedshiftToS3Operator. I don’t understand how to use my parameters into my query. Here is my query into a mycode.sql file: Select * From my_table where date_start = {{ data_interval_end.subtract(days=day_as_parameters)}} Using the Operator like this : unload_data_to_s3 = RedshiftToS3Operator( task_id="unload_data_to_s3", s3_bucket=S3_BUCKET,… Read More Airflow RedshiftToS3Operator: using parameters

Loop over host_vars of hosts in an ansible hosts group in jinja

Advertisements Setup Inventory My inventory contains two groups: worker and main. Worker contains 5 nodes and main contains 1 node. Host_Vars Every node has a host_vars file containing name and description. What I am looking for Jinja A Jinja template that loops over the host_vars of all nodes in a group. Pseudocode I would like… Read More Loop over host_vars of hosts in an ansible hosts group in jinja

is it possible to access JavaScript variables in Jinja?

Advertisements How can I access javascript variables in the jinja template? Example: <script> let data_str = "video1"; let url = `{% url "renderVideo" args="${data_str}" %}` </script url: path("videoplay/<str:args>", views.videoplay, name="videoplay") Traceback: Internal Server Error: /videoplay/${data_str} I’m expecting /videoplay/video1 but it is not parsing the JavaScript variable. >Solution : TL;DR: No, Jinja and JS are separate… Read More is it possible to access JavaScript variables in Jinja?

Stripping out Babel in Flask Jinja Template

Advertisements I’m working with this tutorial which has the following lines: {% set user_link %} <span class="user_popup"> <a href="{{ url_for(‘main.user’, username=post.author.username) }}"> {{ post.author.username }} </a> </span> {% endset %} {{ _(‘%(username)s said %(when)s’, username=user_link, when=moment(post.timestamp).fromNow()) }} It looks this was specifically because he uses Babel translate, which he talks about on his blog. My… Read More Stripping out Babel in Flask Jinja Template

How to Negate in this Jinja if condition?

Advertisements I have this in template: {% if cell %}{% set cell = "b" %}{% endif %} What is contradiction of above conditional? This not works: {% if !cell %} >Solution : You might use not word, consider following simple example import jinja2 template = jinja2.Template(‘cell {% if not cell %}negated{% endif %}’) print(template.render(cell=True)) #… Read More How to Negate in this Jinja if condition?

How can set jinja variable in javascript function?

Advertisements function show_modal(val1, val2){ {% set msg1 = val1 %} {% set msg2 = val2 %} document.getElementById(‘id01′).style.display=’block’ } I have calling show_modal() function in some where in the template. Needs each time assigning situational values to msg1 and msg2 Not working. Each not working below: function show_modal(){ {% set msg1 = "Delete Column" %} {%… Read More How can set jinja variable in javascript function?

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

Advertisements 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 = "." loader = FileSystemLoader(searchpath=path_dir) env = Environment(loader=loader) template = env.get_template("cfg.jinja2") data = template.render()… Read More Difference of writing jinja2 macro in one line V.S. writing macro in multiple lines?