Questions tagged [jinja2]

Jinja2 is a fast template engine for Python. It has full Unicode support, auto-escaping, inheritance, macros, and many other features.

Jinja2 is a fast template engine for Python. It is the default template engine in , can be integrated in other frameworks such as , or can be used without a framework. Features include:

  • Compose complex pages by inheriting from or including other templates
  • Automatic HTML escaping to prevent cross site scripting
  • Write reusable template macros and import them in other templates
  • Call functions with positional and keyword arguments
  • High performance with just in time compilation to Python bytecode
  • Optional ahead of time compilation
  • Optional sandboxed execution environment
  • Wide range of helpful functions for template designers
9474 questions
3
votes
1 answer

Applying a jinja filter after using groupby filter

I have a list of dictionaries that I want to group by a certain attribute and then sum by another. For a variable 'foo' this would be something like: foo | groupby('a') | sum(attribute='b') This clearly won't work because after the groupby, I have…
Gaurav Jain
  • 33
  • 1
  • 4
3
votes
3 answers

Bottle py and Jinja2 global variable

I am using bottle.py framework along with Jinja2 templates in a new application. Whenever a user logs into the application I would like to add a new global Jinja2 variable with the name of the active user, so in a partial template (the header) I can…
Roland Pish
  • 815
  • 1
  • 9
  • 21
3
votes
1 answer

In python the Jinja2 template returns a backslash in front of a double quote, I need to remove that

One of the lines in my jinja2 template needs to return STACKNAME=\"",{"Ref":"AWS::StackName"},"\" Putting the above into the template returns STACKNAME=\\\"\",{\"Ref\":\"AWS::StackName\"},\"\\\" I tried creating a variable DQ = '"' and…
efreedom
  • 253
  • 3
  • 8
3
votes
1 answer

Call Flask functions inside templates

I'm working on my website with Flask and Jinja templates, and I have an odd bug about including images in templates. I have a post.html template that inherits from a base.html, and it gets passed a post object from an SQL database. The problem is…
Brady S
  • 33
  • 1
  • 5
3
votes
1 answer

Saltstack load pillar in a for loop

I am developing a automatic proftd installation whit Salt, i wont to get the ftp users from a template but I cant get work the pillar, i initialized the pillar whit the users data and call it into a for loop, but you don't get the pillar user data…
feb992
  • 43
  • 1
  • 1
  • 6
3
votes
1 answer

How to flush early with Flask / Python / Jinja

You can make a website seem much faster by sending the first part of the HTML response (e.g. the .. that includes the JS/CSS links) right away, while the rest of the response is being computed. (See…
Dustin Boswell
  • 6,114
  • 7
  • 28
  • 26
3
votes
1 answer

Populate WTForm MultiCheckboxField with Flask-Principal Roles

I'm working on an edit user page for my flask app, and I can't seem to figure out how to render the user's current roles like I do other variables, such as email. Here's my models, form, and view: #Flask-Principal Role Model class Role(db.Model,…
Chockomonkey
  • 3,895
  • 7
  • 38
  • 55
3
votes
1 answer

How to display a date_time field in jinja2 template? (flask)

I have a form with these two values (ndb is the Google App Engine ndb model): model: class Appointment(model.Base): start_time = ndb.DateTimeProperty(required=True) end_time = ndb.DateTimeProperty(required=True) form (using wtforms): class…
Nima
  • 1,470
  • 2
  • 17
  • 25
3
votes
1 answer

How to determine if it is an AJAX request in Flask

I am planning to use same templates (Jinja 2) for AJAX and normal requests. If it is an AJAX request I will not use extends and for normal request extends would be used for extending the base template. My problem is, how do I differentiate between a…
Vivek Jha
  • 1,520
  • 3
  • 16
  • 26
3
votes
1 answer

Introspection in Jinja template in SaltStack

We'd like to add some boilerplate information to file written to minions via Salt; basically, notice that the file is managed by Salt, and the state that generates it. I can't find the state information. It doesn't appear to be in opts. salt-call…
3
votes
0 answers

Jinja2 performance

about one year ago, we adopted Jinja2 as our template engine for python. Since this adoption, we are dealing with constant high CPU loading. It's normal a Jinja template compiled and cached, with simple loops and some filters use around 30% of CPU…
Andre Pastore
  • 2,841
  • 4
  • 33
  • 44
3
votes
1 answer

How to assign a variable to another variables in Ansible in a correct way?

I've faced an unexpected problem with Ansible. Here's simplified example. I have defined some global variables in groups_vars/all file like this: --- node01: {ipv4_address: '10.10.10.1', some_info: data} And use it like this in inventory…
3
votes
1 answer

How do I use the IP addresses of machines matching a grain in a Salt State file

I'm creating a formula/state file that adds an iptables rule: ipt_allow: iptables.append: - table: filter - chain: INPUT - jump: ACCEPT - match: state - connstate: 'NEW,ESTABLISHED' - dport: 6666 - proto: tcp -…
Alaa Ali
  • 896
  • 1
  • 12
  • 24
3
votes
1 answer

How to get current url in Google App Engine python with jinja templating

I'm using Google App Engine for Python with Jinja2 templating. Is there a template tag to get the URL of the current page. Or do I have to pass the url as a variable to the template from the view code?
David Xia
  • 5,075
  • 7
  • 35
  • 52
3
votes
1 answer

Code blocks in Jinja templates in salt

I have a block that looks like this: {% if grains['function'] == 'production' %} {% set conf_src = "prod.yml.ninja" %} {% elif grains['function'] == 'staging'] %} {% set conf_src = "staging.yml.ninja" %} {% elif grains['function'] == 'dev'] %} {%…
jcity
  • 826
  • 1
  • 9
  • 13
1 2 3
99
100