templates

'if' statement in jinja2 template

'if' statement in jinja2 template Question: I’m trying to write an if statement in jinja template: {% for key in data %} {% if key is ‘priority’ %} <p>(‘Priority: ‘ + str(data[key])</p> {% endif %} {% endfor %} the statement I’m trying to translate in Python is: if key == priority: print(print(‘Priority: ‘ + str(data[key])) …

Total answers: 2

How to load jinja template directly from filesystem

How to load jinja template directly from filesystem Question: The jinja API document at pocoo.org states: The simplest way to configure Jinja2 to load templates for your application looks roughly like this: from jinja2 import Environment, PackageLoader env = Environment(loader=PackageLoader(‘yourapplication’, templates’)) This will create a template environment with the default settings and a loader that …

Total answers: 5

Pyinstaller Jinja2 TemplateNotFound

Pyinstaller Jinja2 TemplateNotFound Question: I am using pyinstaller to build my flask application, everything is working fine except I get problems with Jinja2 templates. It gave me jinja2.exceptions.TemplateNotFound, I tried to put from app import template which is the templates folder, but it didn’t work (I guess since they don’t contain any py file). I …

Total answers: 3

How to access the next and the previous elements in a Django template forloop?

How to access the next and the previous elements in a Django template forloop? Question: What is the best way to get previous and next elements in Django forloop? I’m printing a list of elements and want child element to be in div-block. So I want something like this: {% for element in list %} …

Total answers: 2

Django print sqlite db data in template

Django print sqlite db data in template Question: I’m new to django and I’m having a little difficulty getting my database data to print onto my page. I’d appreciate help – and I know I’m doing something silly but I’ve kinda hit the wall. I have the DB set up and I can access the …

Total answers: 1

Is there an idiomatic file extension for Jinja templates?

Is there an idiomatic file extension for Jinja templates? Question: I need to programatically distinguish between Jinja template files, other template files (such as ERB), and template-less plain text files. According to Jinja documentation: A Jinja template doesn’t need to have a specific extension: .html, .xml, or any other extension is just fine. But what …

Total answers: 8

Django: Loading another template on click of a button

Django: Loading another template on click of a button Question: I’ve been working on a django project for a few weeks now, just playing around so that I can get the hang of it. I am a little bit confused. I have a template now called “home.html”. I was wondering if there is anyway for …

Total answers: 3

How to structure dynamic javascript creation in Flask?

How to structure dynamic javascript creation in Flask? Question: I’m building a website using the (excellent) Python Flask framework in which there is a templates/ folder and a static/ folder. As the names suggest, the templates folder contains the templates which are rendered through the jinja2 templating engine and the static folder contains static content …

Total answers: 2

Flask raises TemplateNotFound error even though template file exists

Flask raises TemplateNotFound error even though template file exists Question: I am trying to render the file home.html. The file exists in my project, but I keep getting jinja2.exceptions.TemplateNotFound: home.html when I try to render it. Why can’t Flask find my template? from flask import Flask, render_template app = Flask(__name__) @app.route(‘/’) def home(): return render_template(‘home.html’) …

Total answers: 15

How can I iterate multiple key from a dictionary in Django template

How can I iterate multiple key from a dictionary in Django template Question: I have given data from views to template in django. I want to iterate these multiple keys to build a html table. views.py data={‘pacientes’:p,’inicios’:i,’finales’:f,’enfermedad’:enf} # p, i and f are lists return render(request,’verEnf.html’,data) I want to do something like index.html <table> {% …

Total answers: 2