Fix Python – How to load jinja template directly from filesystem

The jinja API document at 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 l….

Fix Python – Flask raises TemplateNotFound error even though template file exists

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__)

def home():
return render_template(‘home.html’)


Fix Python – Django template how to look up a dictionary value with a variable

mydict = {“key1″:”value1”, “key2″:”value2”}

The regular way to lookup a dictionary value in a Django template is {{ mydict.key1 }}, {{ mydict.key2 }}. What if the key is a loop variable? ie:
{% for item in list %} # where item has an attribute NAME
{{ mydict.item.NAME }} # I want to look up mydict[item.NAME]
{% endfor %}

mydict.item.NAME fail….