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
0 answers

Jinja 2 block inside macro?

I have base template that contains macro like this {%- macro local_vars(d) -%} {%- block local_vars %} {% endblock -%} {%- endmacro -%} So I would like to override this block in the child template and still use the variable "d" from the base…
Alen
  • 55
  • 6
3
votes
3 answers

How process variables in Pelican templates?

I define a variable in a pelican article using for instance Markdown syntax: Motto: _"Paranoia is a virtue"_ Anonymous, 1984 Then I want to use it in a template (ex. article.html) as: {% if article.motto %}

{{ article.motto }}

{% endif…
exedre
  • 31
  • 3
3
votes
2 answers

Flask Templates couldn't load css

I followed this tutorial for develop templates with flask http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-ii-templates My file tree is the next one: /static /js bootstrap.min.js jquery_1.11.3.js /css …
Ulyarez
  • 155
  • 1
  • 2
  • 10
3
votes
2 answers

How to use nested if inside jinja2 filter

I am a writing a template file for virtual host and DNS inside the file should change as per environment host-name.Below is problem i am trying to solve: server { listen 80; charset utf-8; server_name "{{ 'a.com if…
thinkingmonster
  • 5,063
  • 8
  • 35
  • 57
3
votes
2 answers

How do I prevent ansible templates from being confused by the content they receive?

I am using ansible to provision wordpress installs, and to do so I have a template for the wp-config.php. My wp-config.php.j2 template has a substitution for the keys and salts, it looks like this {{ wordpress_keys.content }} the wordpress_keys…
jschank
  • 554
  • 1
  • 5
  • 16
3
votes
1 answer

Flask and Jinja2 with bleach, image HTML not working

I have been creating a small blog for myself for a project, only I, as the user, can access the posting page. I had previously been following a Flask tutorial, the end product of which enables you to post HTML and pass it through the Jinja2…
user3015175
  • 163
  • 1
  • 3
  • 17
3
votes
2 answers

How to get a Python dict into an HTML template using Flask/Jinja2

I'm trying to use a Python dict in an HTML file. The dictionary is passed to the HTML template through the render_template function in Flask. This is the format of the dict: dict1[counter] = { 'title': l.getTitle(), 'url': l.getLink(), …
Alice1
  • 33
  • 1
  • 3
3
votes
0 answers

How to add jinja2 extension to the custom CKAN theme?

Is there any way to add Hamlish-jinja extension to my custom CKAN theme without editing CKAN files? I was able to make it work by editing CKAN ckan/config/environment.py (after line 334) file. # Create Jinja2 environment env =…
Kate Kasinskaya
  • 823
  • 10
  • 10
3
votes
1 answer

How can a custom jinja2 tag interface with the context of a flask request

I'm writing a custom jinja2 extension to use in flask applications and I'm looking for a way to access the templates context data using the tag I'm implementing. That is, I want the extension tag to use context params passed into the…
sa125
  • 28,121
  • 38
  • 111
  • 153
3
votes
2 answers

saltstack - Passing variable contains single, double quotes, space, ... to cmd.script?

I have a script that use logger to simulate some "fake" logins: #!/bin/bash {%- set maxretry = salt['pillar.get']('fail2ban:maxretry', 3) %} tag="$1" message="$2" logger -p auth.info "The {{ maxretry + 1 }} \"$tag\" below lines are generated by…
quanta
  • 3,960
  • 4
  • 40
  • 75
3
votes
4 answers

How to handle attribute access errors in Jinja2?

I've got this: template = '{{invoice.customer.address.city}}' And it works fine. But sometimes invoice.customer is Null or invoice.customer.address is Null and then jinja throws jinja2.exceptions.UndefinedError: 'None' has no attribute 'address'…
AlexVhr
  • 2,014
  • 1
  • 20
  • 30
3
votes
1 answer

Create Jinja2 macros that put content in separate places

I want to create a table of contents and endnotes in a Jinja2 template. How can one accomplish these tasks? For example, I want to have a template as follows: {% block toc %} {# ... the ToC goes here ... #} {% endblock %} {% include "some other…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
3
votes
1 answer

Hack Jinja2 to encode from `utf-8` instead of `ascii`?

Jinja2 converts all template variables into unicode before processing. Can anybody find a place where does this happen? The problem is that it assumes that strings are ascii, but we (at Roundup) are using utf-8 internally and our ORM (HyperDB)…
anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140
3
votes
1 answer

How to mark string for translation in jinja2 using trans blocks

I am using django and jinja2 and have something like this in one of my html pages

Q. {{ _("What products will you accept?") }}

A: {% trans myurl=request.url('start') %}A list of qualifying…

3
votes
1 answer

Using Polymer with App Engine Python Jinja2 Templating, passing Datastore values to polymer elements

I have a question regarding how to handle datastore data coming from a Google App Engine python project with Jinja2 templating for use in a custom Polymer element. I am using the simple getting started demo on the Polymer website. I have…
1 2 3
99
100