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

Github Flavored Markdown in Python

Is there a way to parse a text file to output styling of Github Flavored Markdown (GFM) in python 2.7? There are plenty of examples on this site and elsewhere that provide the pygments/jinja2 syntax highlighting guide like this: {% highlight…
Jared
  • 3,651
  • 11
  • 39
  • 64
3
votes
1 answer

python, flask, and jinja2: passing parameters to url_for

I have this: {{ url_for('static', filename='css/main.min.css') }} But I also have a timestamp in the template I would like to pass to prevent caching, like: {{ url_for('static', filename='css/main.min.css?timestamp=g.timestamp') }} Which obviously…
Wells
  • 10,415
  • 14
  • 55
  • 85
3
votes
1 answer

Peewee - invalid literal for int() with base 10: '' when looping over query

I'm trying to loop over a Peewee query object and I am getting the following error when I attempt to visit the template where the query is looped over: ValueError: invalid literal for int() with base 10: '' You'll see below the full traceback and…
Joey Orlando
  • 1,408
  • 2
  • 17
  • 33
3
votes
1 answer

How to extend jinja block template and use it multiple times

Base.html extends into create.html base.html {% block title %}Index{% endblock %} {% block body %}

Index

Welcome to my awesome homepage.

{% endblock %} create.html {% extends "base.html" %} {%…
user3145195
  • 45
  • 1
  • 7
3
votes
1 answer

d3 in Flask, with Jinja

When I put my d3 code directly into my base.html, it runs with no issues, however when I place it into an extending template, nothing shows up except the static text from the template. I'm not importing any data. I've tried moving my script tags…
fstopzero
  • 1,073
  • 2
  • 10
  • 24
3
votes
2 answers

Encountered unknown tag 'with'

I am encountering the following error when attempting to use jinja2 templates with django 1.8 "Encountered unknown tag 'with'". The same template works fine on my flask application but when attempting to use the with functionality of jinja 2 I get…
Moylin
  • 737
  • 1
  • 9
  • 20
3
votes
3 answers

Ansible: How can I set serial numbers for hosts

I am trying to provision hosts on EC2, so I am working with Ansible Dynamic Inventory. What I want to do is; to set serial number for each node. For example: "myid" configuration of Zookeeper Zookeeper requires serial number named "myid" for each…
ai0307
  • 4,037
  • 2
  • 13
  • 21
3
votes
1 answer

Does jinja2 have filter help show only part of variable in browser

If I use {{ post.body_html | safe }} program will select data from MySQL and display on browser as complete article. So does jinja2 have filter help show part of variable like article's first paragraph.
大易归真
  • 545
  • 1
  • 5
  • 15
3
votes
1 answer

Create content snippet with Jinja filter

I want to create content snippets for my home page. An example post looks something like

Your favorite Harry Potter characters enter the Game of Thrones universe, and you'll never guess what happens!

...they all die

On…
kai
  • 1,288
  • 3
  • 12
  • 24
3
votes
1 answer

Set flag in Jinja2 loop, access outside of loop

I would like to set a flag inside a Jinja2 template for loop and later display something or not depending on the flag like so: {% set foobar = False %} {% for foo in foos %} [... render the foo here ...] {% if foo.bar %} {% set foobar =…
NiklasMM
  • 2,895
  • 2
  • 22
  • 26
3
votes
1 answer

Jinja2 - Override block tag inside include?

Having trouble overriding a block tag inside my include. I have base.html
{% include 'snippet.html' %}
snippet.html

{% block h1 %}{% endblock h1 %}

index.html {% extends 'base.html' %} {% block h1 %}Hello World{% endblock…
anthony-dandrea
  • 2,583
  • 7
  • 26
  • 46
3
votes
1 answer

How to call django-pipeline compressor with jinja2 templates

I wish to compress the JS and CSS in my Jinja2 based Python project for Google App engine. I have installed django-pipeline, and added it to my project path. Some of the documentation is not clear to me. Particularly Jinja2 usage. For Django…
intotecho
  • 4,925
  • 3
  • 39
  • 54
3
votes
1 answer

In jinja2, how to include the same template twice but pass in different variables

In jinja2, I am trying to dynamically create a html document using the template more than once. My python script looks like this: # In my python script env = Environment() env.loader = FileSystemLoader('.') base_template =…
Alby
  • 5,522
  • 7
  • 41
  • 51
3
votes
1 answer

How to implement Django-like tags in Jinja

I would like to implement similar functionality to Django template's custom tags in Jinja. In Django templates, to have a server-side function return a string and have it inserted to a template, you can do something as simple as this: from django…
hyperknot
  • 13,454
  • 24
  • 98
  • 153
3
votes
4 answers

Django messages framework with built-in Jinja2 backend

How can I use the Django messages framework with Jinja2 and the built-in Jinja2 backend in Django 1.8? I tried doing it as before, but then remembered that the Jinja2 backend doesn't have the context processors of Django Templating Language. Is it…