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

Setting base file path when doing simple Templating with Jinja2

I am using Jinja purely for creating template. Here is the scheme I have: page1.html {% extends "base.html" %} {% block body %}
neversaint
  • 60,904
  • 137
  • 310
  • 477
3
votes
1 answer

Python Flask: Different render_template for Get and Post Methods Possible?

I have a template (index.html) that I would like to display on GET and the same template, with a variable added, on POST. app.py: from flask import Flask, render_template app = Flask(__name__) @app.route("/") def hello(): return…
anon
3
votes
2 answers

Code seems messy; asking if there is a better way

New to building front-end web and this will be my first time raising a question here. I am using Flask to try it out but my code seems a bit of a mess. Is there a simpler way to implement this code? {% for data in dataList %} …
Mike
  • 43
  • 6
3
votes
2 answers

How do I override a template on readthedocs?

I recently added sphinx documentation for blowdrycss to readthedocs. I want to override the layout.html template on readthedocs. My current template override works fine on localhost, but not on readthedocs. The project uses the Alabaster theme which…
nu everest
  • 9,589
  • 12
  • 71
  • 90
3
votes
1 answer

What would be the right way to render jinja2 template in the pyramid view for an e-mail message?

I use pyramid_mailer package to send emails in my pyramid app. I found examples, where as body for an e-mail were used only simple strings. Obviously, in the real app, I need to use more complicated templates, with information populated in the view…
Jun Murakami
  • 815
  • 1
  • 9
  • 17
3
votes
2 answers

How can I print a jinja dict in a deterministic order?

I have a configuration file where a particular setting takes a long ugly json-style dictionary. I would like to define this dictionary in YAML and print it out with Jinja. Currently this looks something like this: {%- load_yaml as some_conf_val…
Andrew
  • 4,058
  • 4
  • 25
  • 37
3
votes
1 answer

Flask: show flash messages in alertbox

I've been working on flask and I came across flash. It displays a message on page if flash was called on the server side. However, I'd like to display the contents get_flashed_messages() in an alertbox. I tried to make JS function and pass…
mini.1601
  • 157
  • 1
  • 2
  • 12
3
votes
1 answer

Getting svg stored in a variable in jinja2

I'm trying to get an alphanumeric-encoded barcode using the viivakoodi library. I got the barcode which I needed but I'm not able to display it in my HTML page using Jinja2. Here's my code: import barcode from StringIO import StringIO encoding_std…
Prasad
  • 61
  • 1
  • 4
3
votes
2 answers

Access jinja2 globals variables inside template

I have a Flask app I'm building and I'm having issues accessing my jinja2 globals variables from within my templates, any idea as to what I'm doing wrong here? __init__.py from config import * ... #Initialize Flask App app =…
Joey Orlando
  • 1,408
  • 2
  • 17
  • 33
3
votes
1 answer

Flask|Jinjia2|Javascript: Passing Flask template variable into Javascript

What is the best way to pass a variable from a Flask template into the Javascript file? Here is my code I have a simple view in my webapp: @webapp.route('/bars') def plot_d3_bars(): return render_template("bars.html", calendarMap = calendarMap) I…
boba bros
  • 31
  • 2
3
votes
2 answers

Jinja/Wtform aria-required validation

I have a front-end that generates bootstrap forms via a simple macro: {% macro render_field(field, class_='', label_visible=true) -%}
{% if (field.type != 'HiddenField' and…
Tim
  • 2,000
  • 4
  • 27
  • 45
3
votes
3 answers

Get multiple values from one HTML input through Python Flask

I have a dynamically generated number of rows containing text boxes in a table with a default value (order_quantity). Basically on a post I want my items table in sql to be updated with the values of these text boxes according to their ID's. {% for…
Simon Melouah
  • 642
  • 4
  • 11
  • 24
3
votes
1 answer

sendgrid python api unsubscribe and manage list tags

I'm using the sendgrid python api (i.e. I upload html using the set_html method, and i'm trying to customize the style of the default text for the following: "Unsubscribe From This List | Manage Email Preferences" I've tried using their 'Tracking'…
matthewlent
  • 549
  • 4
  • 18
3
votes
2 answers

Ansible Jinja2 template conditionals in for loop

I have a jinja2 template designed to print out the IP addresses of ec2 instances (tagged region: au) : {% for host in groups['tag_region_au'] %} My problem is I can't for the life of me work out how to include only hosts that exist in one group and…
Hilton D
  • 31
  • 1
  • 4
3
votes
0 answers

Date is less than specified date in Jinja

I have a Jinja template where I want to display a message for users that were created before a specified date. I only have control over the template file. What are my options to accomplish something like the following. {% if sub.start_date <…
JustMaier
  • 2,101
  • 21
  • 23