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

Preserve newlines in file rendered to HTML with Jinja

I am trying to print the content of a file in a web page. I want to print each line from the file on a separate line, but instead the line breaks are missing. How do I print the file and preserve newlines? @app.route('/users') def print_users(): …
chahra
  • 105
  • 1
  • 4
  • 11
3
votes
1 answer

Jinja2/Python insert a image(s) into html

I am just looking into using Jinja2 with a python application I have already written. I may be going about this in the wrong way, but here is what I would like to do. from jinja2 import Environment, FileSystemLoader from weasyprint import HTML env…
user3582887
  • 403
  • 3
  • 6
  • 19
3
votes
1 answer

Create a JSON file from a Flask view to be used with D3

I need to use a JSON file created by one of the views in some D3 code in a template. I can load the file with D3 with d3.json("nameOfTheFile.json", function (error, data) { // ... } How can I create and serve this file from a Flask view? When I…
3
votes
2 answers

Display textfield with line breaks in Flask

I have a form with textfields in Flask, and users enter texts line by line. When I look at the DB the enties are stored with line breaks but when I display it on my website, in Flask templates, it just joins the sentences and I couldn't display the…
Bassie
  • 83
  • 9
3
votes
2 answers

babel flask jinja javascript hell

Is there a way for me to include flask jinja enclosed babel translations inside of my javascript file and load it in as if it was a static file? Or is the only way for me to do this to include this part of my code in the .html template file? I'm…
user805981
  • 9,979
  • 8
  • 44
  • 64
3
votes
0 answers

Pycharm, how to allow jinja2 code in python file

At the moment, we are using jinja2 to generate python code. And the file would have both jinja template code and python code as well. The problem is pycharm (we use community edition) are not happy with this. It's mark it as a syntax error, that is…
trongd
  • 273
  • 2
  • 9
3
votes
2 answers

Get Error: jinja2.exception.TemplateAssertionError: no filter named 'basename'

I get this type of error while creating template file. I have simple use this type of syntax: {{ "hello\how\are" | basename}} Please help me solve it. Thanks
akash jivani
  • 41
  • 1
  • 1
  • 2
3
votes
1 answer

Using links with babel in Jinja2

Currently I'm using Flask and Jinja2 in combination with Babel. So far everything is working great. The only problem I'm facing is when using links in a translated text. Let's say we have the following in HTML:

You can change this in your

Thorchy
  • 175
  • 10
3
votes
1 answer

Invalid block tag on line 3: 'raw'. Did you forget to register or load this tag? with Django 1.9 and Jinja2

I am a beginner in Django 1.9 and Jinja2. I have been trying to implement Jinja2 in Django 1.9, but I keep receiving the error as below: Invalid block tag on line 2: 'raw'. Did you forget to register or load this tag? The code that giving problem…
Harris Law
  • 31
  • 1
  • 4
3
votes
1 answer

Retrieve dictionary value jinja

I have a python Dictionary that looks like this [{"hat": 91, "d1b": 2, "d1c": 1, "d1d": 5, "d1e": 7, "d1f": 77, "d1e": 999} {"hat": 1, "d2b": 2, "d2c": 3, "d2d": 4, "d2e": 5, "d2f": 6, "d2e": 7} {"hat": 1, "d3b": 2, "d3c": 3, "d3d": 4, "d3e": 5,…
jumpman8947
  • 249
  • 3
  • 6
  • 13
3
votes
2 answers

getting json dictionary values, though python and jinja

I have a dictionary in json that Im passing though into jinja using python. The page is not working not sure if this is the correct syntax {% with open(jsonobject, 'r') as f json_data = json.load(f) for a, (b,c) in json_data.items()…
jumpman8947
  • 249
  • 3
  • 6
  • 13
3
votes
0 answers

How to call external Jinja2 environment

I'm trying to call an external module to get a template rendered. The external module uses Jenja2 environment to render the template. The code in the external module looks something like this: def get_content(): _jinja_env = Environment( …
wayne
  • 191
  • 1
  • 1
  • 9
3
votes
2 answers

How to add more than item to the session in Flask

I've created a add-to-cart in my website and it works just great. Am using Jquery.getJSON to make the request to get the value of the chosen product, here is the code: $(function() { $('a#process_menu').bind('click', function() { …
Reznov
  • 175
  • 1
  • 3
  • 14
3
votes
2 answers

Ansible get other group vars

I'm digging into Ansible capabilities a bit further, and I'm looking to implement with a beautiful manner the concept of VIP. To do so, I implemented this variable in the group_vars of my inventory: group_vars/firstcluster: vips: - name:…
moutonjr
  • 223
  • 1
  • 3
  • 17
3
votes
1 answer

Jinja2 api: how to get the inherited template of a template?

A template file: {% extends "base.html" %} The templates are loaded like the following: env = Environment(loader = FileSystemLoader(['_templates'])) template = env.get_template('test.html') How can I get the parent template object, i.e., the…
xuhdev
  • 8,018
  • 2
  • 41
  • 69