Questions tagged [jinja2]
Jinja2 is a fast template engine for Python. It has full Unicode support, auto-escaping, inheritance, macros, and many other features.
9,544
questions
0
votes
0
answers
17
views
jinja2-cli how to get env variable into the template
I have a jinja template defined as deployment.yml.j2 with
environments:
default:
databricks_host: data
jobs:
- test: "{% lookup('env', 'ENVIRONMENT_TYPE') %}"
The variable ...
0
votes
0
answers
19
views
Nested Loops - saltstack
Do you know a workaround to fix the bellow code?
Change the dir jinja variable to test it works fine.
{% for dir in ['test', 'test1'] %}
{% set files = salt['cmd.shell']('ls /tmp/{{ dir }}/backup/') %...
-3
votes
0
answers
27
views
Ansible filter and and adding new variable based on condition [closed]
Is it possible to set up a status variable based on condition?
- name: Get all Certs and their details
set_fact:
certs_info : "{{ certs_info | default ([]) + cli_facts | json_query(...
0
votes
1
answer
34
views
Jinja YAML Templating: Get Value of Optional Nested Key or Use Default Value
I'm trying to create a YAML file from some inputs passed to a Jinja template. I want certain input chained keys be optional and used in the templating if present, but otherwise ignored. In the example ...
0
votes
0
answers
14
views
Try catch in jinja dbt Macros
I am trying to achieve try catch functionality in jinja inside dbt macros.
But it seems like jinja doesn't support it in macros.
Any alternative way I can achieve the same thing?
{% macro ...
0
votes
1
answer
23
views
one and only one line per optional element using jinja
I have three choices, A/B/C. If all are chosen I want to render this:
[
A,
B,
C,
]
If only A and C, I want this:
[
A,
C,
]
If only B, I want this:
[
...
0
votes
2
answers
20
views
How to use Jinja2 inside configs?
I have this code:
{{ config (
materialized = 'incremental',
properties = {
"location": "'s3://iceberg/table_{{trigger.run_started_at}}'
}
The {{trigger....
0
votes
0
answers
19
views
I need the success swa to be shown when entering the password correctly
js
document.addEventListener("DOMContentLoaded", function () {
const botonGuardarCambios = document.getElementById('botonGuardarCambios');
botonGuardarCambios....
-1
votes
0
answers
25
views
Flask preserve nav selections after a reload, post or get response
I'm working on a typical Flask dashboard app using a sidebar nav tree. templates in jinja. I'd like to retain the sidebar selection state after a reload, post or get response. Sense the flask re-...
0
votes
0
answers
20
views
How to get rid of false jinja syntax errors
<button type="button" onClick="deleteNotif({{ notif.id }})">delete</button>
This code underlines the brackets as "," expected. This is a false error because ...
0
votes
1
answer
31
views
Jinja2 filter to find out is any value from a list matches with any value from another list
I am looking for the way to perform the following filter and test without using any custom filters (just built-in filters only)?
list1 = ['playing', 'off', 'off', 'off']
list2 = ['off', 'idle', '...
0
votes
0
answers
25
views
Ansible 2.15 Filter expression is not being evaluated when called from JSON
Environment (I am using ansible-navigator to run playbooks so the environment is within a podman container):
ansible [core 2.15.5]
config file = /etc/ansible/ansible.cfg
configured module search ...
0
votes
1
answer
39
views
Using Jinja templates to display products from a database on a website
There is a function that takes data from the database and creates html code with the required number of buttons,
This code needs to be embedded on the main page
The function returns the following code
...
2
votes
2
answers
66
views
Iterate over a list of lists, assert multiple conditions and render when true in Jinja2
I have the following variables to use in my Jinja template:
list_python_version = [3, 9]
all_python_version = [
[3, 8],
[3, 9],
[3, 10],
[3, 11],
[3, 12]
]
Is there a way to use a ...
0
votes
0
answers
40
views
How to Dynamically Generate (raw) SQL Queries with Multiple Parameters Using Jinja2 and SQLAlchemy in Python
I'm using jinja2 and SQLAlchemy to dynamically generate queries in python, specifically with a postgres db. I'm trying to workout how to render the raw SQL that will be executed by the database.
I'd ...
0
votes
1
answer
22
views
DBT Cloud parse_timestamp on sharded tables
I have a dbt cloud project which queries some BigQuery data, applies some transformations and returns some datamarts. The source data is a collection of sharded tables i.e. GA4 events tables
I want to ...
-1
votes
1
answer
35
views
How to get only id from many to many relationship SQLAlchemy
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
likedComments = db.relationship('Comment', secondary=user_likedComment, backref='likedby')
class Comment(...
1
vote
1
answer
58
views
Match name: of the list1 to a name: of the list2 and get matches from the list2
I am trying to find matches based on list1 name: in list2, but as the result get the dict2 matches. I am using this with Ansible.
list1 :
- name: game1
- name: game3
list2:
- name: game1
...
0
votes
1
answer
26
views
Is there any way to use javascript variables and use them in Jinja?
I want to use my localStorage variable to set the starting class of my sidebar to wether it is collapsed or not making it preserve its state when refreshing or goint to the next link
$(document).ready(...
0
votes
0
answers
25
views
python-docx-template and {%tr for a loop and if condition error
I'm using the python package python-docx-template in a django project.
I'm trying to build a table with a condition to display some rows. I'm trying to nest a '{%tr' of an if statement in a 'for' loop ...
1
vote
1
answer
51
views
How to make use of fileglob & loop while copying files from source to destination with custom names
Below is my set of reference data
id,firstname,secondname,department,subDepartment,salary
ID01,first01,surnam1,HR,pension,30000
ID02,first02,surnam2,IT,development,40000
ID03,first03,surnam3,IT,...
1
vote
1
answer
19
views
How escape : in a when conditional
I'm trying to loop a list and using a when, but if the when has : the Lint fails.
For example:
---
- name: Check variable starts with substring
hosts: all
tasks:
- name: Verify variable
...
0
votes
1
answer
82
views
Cannot insert row in Postgres using Ansible and Jinja
I have an Ansible playbook to backup sono devices, everything seems to work except when I try to insert the backup (and the differences, if any, with another backup) into a Postgres Database for two ...
1
vote
1
answer
82
views
Define variable as list of contents of multiple files
I am trying to declare a host variable in an Ansible YAML defaults file of a role, that should contain the content of multiple files as lists entries.
Consider the files dir/1.txt with the content one ...
0
votes
0
answers
22
views
Can a cookiecutter pre_prompt.py hook access the value of the template's `output_dir`?
I'm attempting to write a simple cookiecutter pre_prompt.py validation script that inspects the parent directory from which the template is being executed.
Unfortunately, I cannot figure out how to ...
0
votes
1
answer
52
views
Ansible: How to determine if a specified host is listed in a list of string arrays?
I want to create a vault (1password, not Ansible vaults) for each host in the inventory.
- name: Get the vault list
ansible.builtin.shell:
cmd: op vaults list
register: vaults_list
This ...
0
votes
0
answers
42
views
sqlfluff ignores everything when jinja code present
I noticed a strange behavior of sqlfluff in dbt. It doesn't show warnings when I add jinja code for incremental refresh.
For example for this code sqlfluff shows warnings (e.g. capitalized commands, ...
1
vote
1
answer
42
views
Testing ansible "to_nice_json" filter within Python - "No filter named 'to_nice_json'"
I want to test an Ansible Jinja2 template using a Python script, based on the answer provided here: How can I test jinja2 templates in ansible?
This code used to work, however I don't remember in ...
0
votes
0
answers
31
views
Jinja - Converting JSON to YAML
I'm trying to convert my JSON input to a YAML format. I only need the key value pair of a few fields from the json but I'm not seeing the output i need. The fields i need as key value in my YAML is ...
0
votes
0
answers
27
views
How to fill dynamically expanding HTML file with templates filled with python data
I have a HTML template for one message (i receive messages via Slack-API).
I want to fill the template with information from API and than stick templates together, in new HTML file (Output file will ...
1
vote
1
answer
59
views
dbt pre hook deleting a table that was not built yet
This is my dbt config
{{
config(
materialized='incremental',
incremental_strategy='append',
pre_hook='DELETE FROM {{ this }} WHERE r_date <> CURRENT_DATE
)
}}
This model is to ...
0
votes
1
answer
25
views
Jinja2 syntax issues when using inline styling for HTML
I am passing a randomly generated value from my backend python to my html template
card_heights = [random(300, 340) for _ in range(len(games_list))]
return render_template('search_results.html', list=...
0
votes
1
answer
45
views
Let user update any number of rows in a dynamic table using Flask
I'm trying to code a database powered web application with Flask/Python + SQLite back-end and HTML/CSS/JS front-end (Bootstrap). In one section, user should be able to change any number of fields at ...
0
votes
0
answers
16
views
how to display alert messages with jinja2? [duplicate]
I'm building a todo app with fastapi. I've been trying to display alert messages with jinja2 'TemplateResponse' and it partially works, the alert is displayed but I'm redirected to a new page, which ...
0
votes
2
answers
45
views
Render numbers inside an Ansible yaml template
Very close to Create an int var with Ansible's ternary operator and that answer https://stackoverflow.com/a/69109779/446302
In an Ansible project, I'm trying to have a yaml template file with ...
0
votes
0
answers
37
views
Selecting ansible_user in compose based on a ec2 inventory tag
I'm trying to get a list of ec2 hosts that are divided into two groups of tags tag_OS_ec2_user and tag_OS_ubuntu, but there is a problem with determining the value of ansible_user depending on the tag ...
0
votes
0
answers
15
views
Is it possible to call a dbt doc function within another dbt doc function?
DBT's/jinja's doc function allows usage of a doc block, defined in a markdown file. I want to be able to reference a doc block inside another doc block. Is this possible to do?
Desired:
{% docs ...
0
votes
0
answers
29
views
Double Quotes Formatting Issue in Rendered HTML Template - Python FastAPI
I'm encountering a formatting issue with double quotes in a rendered HTML template within a Python FastAPI microservice. The HTML template is stored in a folder called "templates" and ...
2
votes
2
answers
32
views
How do I get a webpage title from an sql database with flask and jinja2?
I have a table where I store the title of a webpage. I have created a function in python that returns the title as a string. In jinja how exactly can I access that function? I don't want to pass the ...
0
votes
0
answers
35
views
Jinja sql - How to mix and match column names and conditionally perform calculations based on multiple list variables
Goal: Using Jinja and SQL, create a template for calculating metrics based on standardized column names.
Use case: us_outlet_dollars + us_fullprice_dollars = us_total_dollars. The code will look for ...
-1
votes
0
answers
26
views
i need help to finguring the problem on this jinja code, am using flask
am a writing an application that draw charts using data from the database,am using flask,in visual studio editor but is all underlined in red,i have installed better jinja and jinja pack extension but ...
0
votes
1
answer
26
views
Construct defaults dynamically with jinja2 in Ansible?
In an Ansible role, my current approach for creating a configuration file is creating a dictionary by merging a dictionary in defaults/main.yml and user set values with the combine filter and let ...
0
votes
0
answers
38
views
How to add a Request Authorization Header using vanilla js for FastAPI and Jinja2 SSR and honoring the user-initiated top-level navigation
I was able to add Request Authorization Header using vanilla js fetch but FastAPI HTMLResponse is treated as text not a navigation object. With fetch the Request Header Sec-fetch-dest is "empty&...
0
votes
1
answer
28
views
Passing a dictionary from pythonFlask to Jinja2, error keeps telling me variable is undefined
Overall my goal is to dynamically update a table in html with data from a dictionary passed through flask into a jinja loop.
In trying to populate an html table with data from a dictionary created in ...
-1
votes
1
answer
22
views
Passing a hidden input value from a looped form
A simplified version of my code:
html
{% for c in categories %}
<form action="" method="post">
{{ form.hidden_tag() }}
<input type="hidden" name="e&...
1
vote
0
answers
20
views
Trying to populate a drop-down menu form element with items from a relationship list
I am working on a simple web app for an online school.
So far, the administrator can create a teacher profile and create and assign a class (lesson) that teacher is responsible for:
class Teacher(db....
3
votes
1
answer
58
views
Loop over a YAML dictionary
When looping over a nested YAML structure I am getting the following error:
[host] (item=script.sh) => {"ansible_loop_var": "item", "changed": false, "item":...
0
votes
0
answers
39
views
Ansible jinja format message in foreach
SOLVED
I have some problem with parsing output with jinja in ansible. I am trying to parse some output from hashicorp vault module, values what I get from direct call to array and what I get after ...
1
vote
1
answer
32
views
How to pivot in DBT without aggregating the value
Using DBT, how does one pivot a table without aggregating? When looking at the pivot macro it mentions the aggregation function, which defaults to sum.
To visualize the problem:
Color
Date
Amount
...
0
votes
0
answers
47
views
Generate network interfaces config using ansible/jinja2
I am trying to generate unique network interface configurations for multiple devices using jinja2 and ansible but it keeps joining the interfaces for each of the items variable.
Expected output for ...