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

How to draw inputs without the id attribute using WTForms?

In my flask application I have to draw a form multiple times on the same page. This leads to the problem where I have multiple input fields with the same id on the page. E.g.: class ChannelForm(flask_wtf.Form): name =…
Georg Schölly
  • 124,188
  • 49
  • 220
  • 267
3
votes
1 answer

Jinja template parses variable as literal string

I'm having a problem where Jinja is treating a variable I'm passing to it as a literal string, which screws up the URL routing work done by Flask. app.py - each "course" has its designated URL, as shown by…
Shrey
  • 522
  • 8
  • 16
3
votes
0 answers

jupyter nbconvert register jinja filter

For the jupyter sas_kernel I'm writing a template for nbconvert (version 4.2.0). The basic layout is as follows: {%- extends 'null.tpl' -%} {# Comment block #} {% block header %} /* coding: SAS utf-8 */ {% endblock header %} {% block in_prompt…
Jared
  • 63
  • 6
3
votes
1 answer

Jinja2 : call function on click

I'm hacking a cms-like system that use Jinja2 and Javascript in frontend and Python in backend. I implemented some Python functions on backend that do stuff on database. I want to launch that functions from HTML pages, so i used Jinja2. The problem…
frapol
  • 31
  • 1
  • 1
  • 2
3
votes
1 answer

how does jinja2 prevent XSS attacks?

According to the Jinja2 docs Link, it provides: powerful automatic HTML escaping system for XSS prevention According to the Flask docs, it prevents XSS attacks by configuring Jinja2 to automatically escape all values unless explicitly told…
Ashwin Kumar
  • 31
  • 1
  • 3
3
votes
1 answer

In a nested for-loop, how can I access the outer loop index in a jinja template?

{{loop.index}} correctly dereferences the innermost loop. I'm not seeing a way to identify which loop index I'd like, however, if I have more than one loop nested. http://jinja.pocoo.org/docs/dev/templates/
tarabyte
  • 17,837
  • 15
  • 76
  • 117
3
votes
1 answer

Treat question marks as part of url in Flask route

I have a route that echoes whatever is passed to a url parameter. If I pass something that contains a question mark, such as /question/What is faster than a speeding bullet? in a browser, the echoed value does not contain the question mark or…
3
votes
1 answer

How to import loopcontrol in jinja2

I need to use break for a for loop in jinja2. Below is my code: {% for i in range (0, desc) %}{{ desclist[i] }} {% set length = length + desclist[i]|length %}{% if length >= 70 %}{% break %}{% endif %}{% endfor %} and to import the loopcontrol…
benbenben
  • 159
  • 1
  • 3
  • 10
3
votes
2 answers

jinja 2 nested dictionaries to yaml

I'm trying to use jinja2 to output a nested dictionary to a yaml file. However I'm not sure how to access the nested dicts. With a flat dict for data I can use the below. - request: path: {{ path }} headers: origin:…
Yunti
  • 6,761
  • 12
  • 61
  • 106
3
votes
2 answers

How can I do line break in jinja2 python?

How can I do line break in jinja2 in python? Below is my code t1 = Template("{% for i in range(0, a1) %}|{{ mylist1[i] }}{% for j in range(0, (20 - (mylist1[i]|length))) %}{{ space }}{% endfor %}|{{ dicts[mylist1[i]][dicts[mylist1[i]].keys()[0]]…
benbenben
  • 159
  • 1
  • 3
  • 10
3
votes
1 answer

How do I inspect Pelican variables

I'm modifying a Pelican template and I have the code below which adds url every time a page is found. I can see that the p object has the attributes url and title. However I only knew this because I copied the code from another template shown below.…
canyon289
  • 3,355
  • 4
  • 33
  • 41
3
votes
1 answer

Best way to format a nested Python dictionary to be rendered in a jinja2 templates

Hi I have a Python nested dictionaries like this: fv_solution = { 'relaxationFactors': { 'fields': { '\"(p|pa)\"': 0.3, 'alpha': 0.1, }, …
efirvida
  • 4,592
  • 3
  • 42
  • 68
3
votes
2 answers

how to combine angular2 with jinja2 templates and flask

I'm getting started on Angular 2 after much success with Angular 1. I followed both the Quickstart and the Tour of Heroes tutorials and everything works like a charm. The lite server gets kicked off, I see tsc running in watch mode and I even see…
lostdorje
  • 6,150
  • 9
  • 44
  • 86
3
votes
3 answers

ansible/jinja2 get unique subelements

I got a list like this: host_depends: - host: abc depends: - name: item1 - name: item4 type: asdf - name: item6 - host: def depends: - name: item2 - name: item4 - name: item6 I need to loop…
Zulakis
  • 7,859
  • 10
  • 42
  • 67
3
votes
2 answers

Generate a static page from a Jinja template and serve it with Flask

I want to create a page that once generated will remain static so my server doesn't waste resources regenerating content. I know about memoizing but was wondering if Flask provides a built-in or different method for this.
muddyfish
  • 3,530
  • 30
  • 37