I’m using Django 1.4/python 2.7.9 (because I’m required to, I know 1.4 is pretty old now) and I’m pretty green with django/python. In my template file, I seem to be unable to use any of the cool conditional tags like ifchanged or ifequal within a for loop. For example: This throws the error “Encountered unknown tag ‘ifchanged’. Jinja was looking
Tag: jinja2
Ansible write variables into YAML file
I have a specific ansible variable structure that I want to get from the vault into a yaml file on my hosts. Lets assume a structure like this: I need something like a “generic” template to output whatever “secrets” contains at the moment, since the content changes almost completely based on the current environment. The easiest solution I can think
Flask cannot import enumerate? UndefinedError: ‘enumerate’ is undefined
I just write this code in a HTML page. So, Flask do not support the enumerate? Answer As Or Duan says, Jinja2 has its own language. Looks like Python but it’s not Python. So the Python enumerate built-in function is not part of Jinja2 template engine. There are, however, some alternatives you can use: If you want to enumerate the
How can I create a form from a list of models using WTForms?
I have a list of Prediction models. I want to bind them to a form and allow the use to post back. How can I structure my form so the post associates a Home/Away score with a Prediction model’s id field for each item I bind to the form? view form template I am unable to get my data to
Sort dict in jinja2 loop
I’m still learning jinja2 and flask and I’m having a difficulty using dictsort in jinja2. So I’m passing this dict into a jinja2 template: What I want is create a table that is sorted by the value of the key ‘totalpts’. I tried all sort of things and it just doesn’t take totalpts into account when “sorting”. Here’s one of
Pass variables to Flask’s render_template
I want to pass multiple variables from my Flask view to my Jinja template. Right now, I can only pass one. How do I pass multiple variable when rendering a template? Answer The render_template function takes any number of keyword arguments. Query for each of the things you need in the template, then pass the results of each query as
How can I pass data from Flask to JavaScript in a template?
My app makes a call to an API that returns a dictionary. I want to pass information from this dict to JavaScript in the view. I am using the Google Maps API in the JS, specifically, so I’d like to pass it a list of tuples with the long/lat information. I know that render_template will pass these variables to the
How do I get my HTML button to delete the right list item from a SQLite database?
I’m a beginner, so forgive any stupidity in advance. I’m using Flask (and by extension Jinja2) to create a simple web app — one that basically lets you type a movie into a web form, which adds it to a SQLite database. I’ve gotten Flask to very nicely iterate through all the movies in the database and print them to
Insert static files literally into Jinja templates without parsing them
I’m trying to insert file into a page using Jinja 2.6 using the include tag. This worked fine until I started using characters in the file that are reminiscent of the Jinja syntax, at which point it realized it couldn’t parse them and bombed. Short of going though the file and escaping all characters, what can I do to tell
How to enable timezones with babel in my jinja filter?
I want to use timezones according to the babel locale. How can I achieve this? The specific situation I have is the goal of displaying the date and time of an article and a humanized and localized way eg: Yesterday 13:21 or if the Swedish language parameter is set it will display Igår 13:21 And if the date wasn’t yesterday