Questions tagged [jinja2]
Jinja2 is a fast template engine for Python. It has full Unicode support, auto-escaping, inheritance, macros, and many other features.
8,450
questions
-1
votes
1
answer
25
views
JS works on some pages but not others... file exists in page source though
I don't know much javascript so I'm pretty much copy-pasting. I'm making a website and there is a navigation sidebar. I have this script to toggle a class the sets display to none.
$(document).ready(...
1
vote
1
answer
18
views
In Jinja2, how to create auto increment numbers?
In a page, I want to display some figures with text prompt. For example:
Figure 1
Figure 2
My code is
{% set num = 0 %}
Figure {{ ++num }}
Figure {{ ++num }}
But it shows
Figure 0
Figure 0
How can ...
1
vote
1
answer
16
views
Convert Ansible variable to integer for arithmetic
I would like to execute a command to obtain the current AWS EC2 launch template version in an integer format so I can do basic arithmetic on it to use in subsequent queries / deletes.
For example:
...
1
vote
1
answer
22
views
Set "selected" tag in responsive dropdown and select using Flask and jinja2
I have a flask server which sends a dictionary of options to a dropdown or selection (in form).
Here is the Python code:
@app.route("/", methods=['GET'])
def index_get():
options = {'o1' ...
0
votes
0
answers
12
views
Why is this jinja2 for loop not working in pyhtml code?
For example if I use a for loop like this it doesnt detect the line between the loop as pyhtml and gives out "Invalid Syntax" error. Is there some compatibility issue or practices I'm ...
0
votes
1
answer
17
views
best practices in structuring jinja templates (flask)
I wrote a site in bootstrap and thinking about refactoring it in jinja.
I am not much familiar with nesting blocks, and the site is relatively simple.
My goal is to save time in maintenance when I ...
1
vote
1
answer
22
views
How do I filter a list through a lookup dictionary in jinja2
How can I filter a list in jinja2 to generate a list of values from a lookup table?
I have a situation where I am using Jinja2 to generate SQL. I have a list of values and I want to replace them with ...
1
vote
1
answer
28
views
loop.nextitem doesn't work with current value from data
I need to compare postback.campaign_id with the value of the next item. If it's similar, then, I don't print nothing, if not, then, print my row.
But, this code outputs everything.
<table>
&...
0
votes
0
answers
10
views
WTForms, Jinja2, Flask - creating subform that is connected to another form
I'm creating a little project that's using MongoDB via flask server on Linux.
Now I'm stuck because I need retrieve data from forms in specific structure that corresponds with MongoDB database.
...
0
votes
1
answer
19
views
How to compare more than two lists have the same values in same indexes in Ansible?
I would like to compare more than 2 lists, and see if they have the same values in same indexes.
I have the previous questions regarding how I can alternate the values in the multiple lists. here
...
1
vote
1
answer
15
views
How to convert a string to dict in Ansible?
I want to convert the simple output of python, and I tried to follow the post here.
But it doesn't seem to work in my sample code. data is a string coming from the output of a shell task.
How do I ...
1
vote
1
answer
14
views
Can I pass non-string types via environment variables to meta.yaml?
I am aware that conda's meta.yaml file uses jinja templating, which allows us to pass values to it via environment variables. For example like this:
package:
name: {{ MY_PKG_NAME }}
version: {{ ...
0
votes
2
answers
21
views
Can jinja2 templates access (and modify) global python script variables?
I would like to create a certain text file structure using python and jinja2. (not HTML). The files are static, and built of several segments, each segment is created by a different jinja template.
...
0
votes
1
answer
20
views
How to filter all list which a key has a specific value/values from lists of dict in Ansible?
I would like to return the lists of a key('minio_vf') has a specific value(True) from the input data. So I used selectattr('minio_vf', '==' ,True) filter to get all list.
Input Data #1 ('minio_vf' key ...
0
votes
1
answer
34
views
Subtract Year from an object in a Django Project
I'm trying to subtract year data from a model object created in a Django project. I would like to obtain a final value comparing a date in an object registered in my model with the value of the ...
0
votes
0
answers
39
views
GCP Composer (Airflow) - passing parameter to job dynamically
I have a requirement wherein i need to pass parameters to an Airflow dag (eg. tenantName), and the airflow dag(python operator) will use the tenantName to filter data based on the parameter passed.
i'...
1
vote
0
answers
20
views
Pagination Links in Python and Flask
I'm building a flask app and I've managed to get some kind of pagination working.
@projects.route('/projects/<int:project_id>')
def projects_pages(project_id):
ROWS_PER_PAGE = 2
page = ...
1
vote
1
answer
24
views
Skip a specifc iteration of an Ansible loop given a condition
I'm attempting to skip an Ansible loop iteration when a specific variable is passed onto the playbook.
I have the following with_items: on an ansible task:
...
...
with_items:
- "item1&...
0
votes
0
answers
14
views
SUPERSET generate SQL template from a loop in python
I want to create a simple sql using jinja templating in superset but this doesn't work.
input
{{n}} -- this is where we set the parameter or range to use
{% for i in range(n): %}
{% s+=f'SELECT i\...
-1
votes
0
answers
17
views
Jinja subtraction and variable declaring
In jinja, how to subtract.
Eg: I have some number inside {{ review.rating }} , and I want to subtract the number with 5.
Is it like {{ 5 - review.rating }} or how?
And is it possible to put the answer ...
0
votes
1
answer
30
views
Looping in jinja
I have a Integer value inside {{ review.rating }} . Now I want to loop using jinja , the number of times the value of review.rating.
Eg. if I have review.rating = 4 , I want to display <div>A<...
0
votes
1
answer
21
views
Sanic how to locate to static file
I want to locate to static file, because there are many relative path in the html, like:
<a href="1.html"> page1 </a>
<a href="2.html"> page2 </a>
....
I ...
0
votes
1
answer
12
views
How to use data file for jinja2 template
I'm creating a python3 jinja2 script that receives as parameters two files:
The template file called depl.yaml.j2
The data file called data.dev
The script is supposed to output a k8s file.
ps. I ...
0
votes
0
answers
17
views
I want to send posts with captcha validation in flask, but when sending, the captcha is reloaded and does not match the one entered in the form
To put it simply: I have code that sends and saves posts using flask and I have code that generates a captcha. Both work separately, I don't know how to make them work together.
Code from flask ...
-1
votes
1
answer
21
views
How to embed your Jinja2 url_for in the style attribute while using flask?
i am new to web development using python and flask. i am working on a sample project but unable to troubleshoot the error shown in the picture.
the error is coming in the style
<header class=&...
0
votes
1
answer
16
views
Operator to concatenate two dbt Jinja sets?
In a given model, I am using two macros to create sets for a later loop.
Adapting the example from the docs, it looks something like this:
{% set pay_1 = ["bank_transfer"] %}
{% set pay_2 = [...
-1
votes
0
answers
20
views
Trying to understand a jinja2 global function declaration and its use in the application
So I've been dumped some Flask/Python code to weed through and it is a bit beyond my understanding...what I'm not sure of is the 'include_raw' Global jinja function...I know that lambda is a function ...
1
vote
1
answer
19
views
Ansible/Jinja: Conditional port publishing in Docker/Podman
My intention is pretty simple: IF I specify a port in my Ansible playbook, expose it in the container being created/updated. Otherwise, do not expose any port.
I think my intention is easier to ...
0
votes
1
answer
23
views
How do I access a context_processor from within a method route in Flask?
I'd like to setup variables available to both my views and my methods without polluting the request object in a before_request decorator.
Context processors seems like a nice way to do this however, I ...
1
vote
1
answer
47
views
How do I pre-select specific values from a dynamically populated dropdown list for HTML form?
I have three drop down lists with identical options, all of which are populated from the database and works fine. I would like to implement a 'smart mapping' feature where the three fields are pre-...
0
votes
1
answer
15
views
using a variable from Database to specify a URL using jinja
I'm trying to define a specific file for a user sample but it doesn't seem to work...
I am making a flask app with cards for users, so I can't define the files in the flask route since the loop for ...
0
votes
0
answers
11
views
Changing a date format from m-d-y to y-m-d in jinja
I want to use the value - 01-01-1990 and format it to 1990-01-01 i'm trying to use the
strftime filter but i think im missing something
0
votes
1
answer
231
views
AttributeError: module 'jinja2.ext' has no attribute 'with_'
I tried to install eli5 Python package via the below command in my google colab file.
!pip install eli5
And I'm getting this error when running the above command.
AttributeError: module 'jinja2.ext' ...
1
vote
0
answers
93
views
Jinja2 not found error when using pycaret
I am trying this code in Google Colab
!pip install pycaret
As part of the install it gives this message
Installing collected packages: jinja2
Attempting uninstall: jinja2
Found existing ...
-2
votes
1
answer
26
views
Accessing key-value on FLASK/JINJA
So my back-end is delivering this to the front:
"results": [
{
"id": 166740,
"usuario": {
"id": 64600,
...
0
votes
0
answers
18
views
converting html table to csv file dose not contain the jinja variables
I am trying to convert html table to csv file to allow users to download the data here is the route code:
@login_required
def yours():
path = "templates/yours.html"
# empty list
...
2
votes
4
answers
49
views
Conditionally add argument to argv
I want to conditionally pass --detach into argv like this:
- name: run docker container with service
command:
args:
argv:
- docker
- run
- "{{ '' if wait else '--detach' ...
1
vote
1
answer
44
views
How to get conf value from airflow dag?
I want to get conf value from dag area.
"{{ dag_run.conf['company'] }}" is recognized as a string.
How can I get this value?
Values are passed fine when calling other dags.
t_trigger = ...
1
vote
2
answers
51
views
How can I alternate the elements of multiple lists in Ansible?
I have multiple lists as input (all lists have the same length, but the input can have more than 3 lists). I want to create a list which is a sum of all input lists alternating their elements.
For ...
0
votes
0
answers
11
views
How to prevent Flask-WTF forms from closing modal when submitting invalid input?
I am trying to build a website where you can upload a video (this already works). But when submitting a wrong file format, the Flask-WTF form closes the modal. I want it to stay open.
(I am trying it ...
0
votes
0
answers
12
views
Passing variables inside jinja2 using double brackets
I have a custom jinja2 tag ('color_function') that color codes each cell (word table) based on its values.
{%tr cellbg value|color_function %} # cellbg adds background color based on the value
I want ...
1
vote
1
answer
30
views
How does Airflow decide to render template values?
I am working with Airflow 2.2.3 in GCP (Composer) and I am seeing inconsistent behavior which I can't explain when trying to use template values.
When I reference the templated value directly, it ...
-1
votes
1
answer
13
views
Unable to make fields and values in italics in html/jinja2
Hello I have the following Html jinja2 template
<h1>Table of contents</h1>
{%- for region, d in data.items() %}
<a href="#{{ pageTag }}-{{ region }}">{{ loop.index }}. TGW ...
0
votes
0
answers
31
views
I need help for this error : Uncaught SyntaxError: missing ) after argument list
Hi i'm trying to take some information from a python list of dictionaries and put them into javascript variables. But i keep getting this error at line 5. Can you help me ?
Here's the code :
const ...
1
vote
1
answer
32
views
Template variable being checked for undefined inside an uncalled function on page load in Jinja
Tech Stack:
My stack is Flask. Python with HTML, CSS, JS.
Background:
I have a variable myList. It's a list and it is passed from python to the frontend. This list is empty at the page load. This is ...
1
vote
1
answer
30
views
Merge 2 json arrays based on their keys
How can I merge 2 json arrays based on the same keys and add a 3rd item from the input json pog_id in the output json file? I have tried with the code mentioned below that is creating 2 different ...
0
votes
1
answer
34
views
JInja2 Template Syntax Error Encountered Unknown tag 'endif'
I am building a basic api based website as I was going to display some info om page and was checking for a condition i encountered --
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag '...
0
votes
1
answer
31
views
Django unable to load svg file in external js file using static reference
I need to load a svg file from my javascript code which I am including in my index.html. I understanding that jinja template cannot be used inside a js external file. And so as a workaround I am ...
0
votes
1
answer
21
views
In salt states, we use "grains.host" to get the host details. How do we get the AWS EC2 availability zone name using salt grains?
In salt states, we use "grains.host" to get the host details. How do we get the AWS EC2 availability zone name using salt grains?
To get the hostname I give the below:
{%- if 'aws-dev-01' in ...
1
vote
1
answer
44
views
Iteration over dictionary
I have setup a Flask app trying to fetch data from the classic Drinks API.
Here is a shortened sample of the output given by this API
{
"drinks": [
{
"idDrink": "...