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

How to write a pretty JSON file from a template in ansible?

I am trying to write a config file using jinja2 templating and save the file as .json and pretty format it. How can I save the output file as a variable and then format it to JSON using to_nice_json? This play is part of a role that is called from…
alig227
  • 327
  • 1
  • 6
  • 17
3
votes
1 answer

python - jinja2 - putting all html from python into one PDF (rather than multiple)

I was given some great code by 'tuomastik' on this site, and have tweaked it slightly to work for me. However, I have spent several hours trying to edit it so it prints to one PDF rather than multiple (one PDF, but each report starting on a fresh…
Nicholas
  • 3,517
  • 13
  • 47
  • 86
3
votes
1 answer

Ansible setting vars from with_items

I am attempting to run a template task per ec2 instance, grabbing variables from other registered variables. The instance date is stored in ec2.tagged_instances, the IP information for the other two interfaces are stored in eni_dc and eni_spoke…
mcaulifn
  • 170
  • 2
  • 8
3
votes
1 answer

Select a radio button in a jinja2 template

I have a jinja2 template with a simple user preferences form. The preferences are passed as a python dictionary into the render_template() function. Depending on a setting, I need to mark one of the radio buttons in a group as checked. Q: How to do…
Marek Jedliński
  • 7,088
  • 11
  • 47
  • 57
3
votes
1 answer

Jinja: if path == '/home' or '/home/'

I am interested in knowing the proper way of performing the following function:
  • %}class="active"{% endif %}> Home
  • The…
    Evan
    • 79
    • 1
    • 6
    3
    votes
    1 answer

    Render WTForms SelectField options with embedded HTML in Jinja

    I am trying to create an option in a SelectField that uses an embedded span in the label. However, the tag is escaped and displayed literally in the field. I've tried Embed HTML tag in Flask WTForms field but it doesn't work in this case (likely…
    3
    votes
    2 answers

    Escaping slashes for Jinja2 and LaTeX

    I am trying to get into report automation with LaTeX and Jinja2 with a python script. I managed to fill a simple table with some data in a .txt file. I would like to use variables names inside my data file containing the character "/". However…
    user43799
    • 31
    • 3
    3
    votes
    2 answers

    Pagination with Pony ORM

    Is there any best practice for pagination with Pony ORM? I'm seeing others have these has_next and has_previous helper methods but in Pony I'm on my own. So far this is what I have, a couple of Jinja helpers: # Jinja helpers for pagination def…
    MGP
    • 2,981
    • 35
    • 34
    3
    votes
    1 answer

    Splitting variable not working in Ansible

    I am trying to split the variable based on delimiter. How can I achieve it? some_module: {{item}}.split('@')[1] with_items: - git@someversionxxx - gradle@someversionxxx I get following error: list object' has no attribute 'split…
    MMA
    • 408
    • 3
    • 7
    • 19
    3
    votes
    1 answer

    Ansible/Jinja2 how to append key into list of dict

    I would like to have dictionary defined in ansible like this vhosts: git_branch_1: - { a: example.com, customer: a } - { a: example.com, customer: b } - { a: example.org, customer: a } git_branch_2: - { a: example.com, customer:…
    adrive
    • 253
    • 1
    • 5
    • 10
    3
    votes
    1 answer

    Django: Views problem with Django + django-registration + jinja

    So, I have a django project that is using jinja2 rendering, and I also installed django-registration to make my life easier. I ran into the following problem: Going to homepage I render it with jinja. In order to check for authentication, I have to…
    mgPePe
    • 5,677
    • 12
    • 52
    • 85
    3
    votes
    1 answer

    Jinja2 compile extension after includes

    In Jinja2, is it possible to have a Node from the AST render after all include statements have completed? This is a key piece of a solution to a bigger puzzle. Example code: x.py from jinja2 import nodes, Environment, FileSystemLoader from…
    Brian M. Hunt
    • 81,008
    • 74
    • 230
    • 343
    3
    votes
    1 answer

    Using Flask url_for in button onclick location.href redirect leads to `Method Not Allowed`

    I'm in the middle of wire-framing out some basic forms and I'm hitting an unexpected 405 Method Not Allowed blocker. Basically I have some html in a jinja template looking like... File Y {{form.pathY…
    jxramos
    • 7,356
    • 6
    • 57
    • 105
    3
    votes
    0 answers

    How to limit text length outputting from database to browser in flask python

    You know how blogs work where a the homepage will vertically display all the posts but it will shorten the text and have a 'read more' link to go to the page of that article. I want to do that with my python/flask app because I don't want it to show…
    hckrieger
    • 81
    • 2
    • 7
    3
    votes
    1 answer

    Looping over items with Jinja, adding in div after every 5th item

    Problem I have a list of 100 golf courses and I'm looking to insert a div, containing an image for an ad after every fifth course. How would I go about doing this? Update #1 content.html (Revised, newest version) I've updated my original code…
    Andrew Nguyen
    • 1,416
    • 4
    • 21
    • 43