I am trying to create an html template in python using Jinja2. I have a templates folder with my "template.html", but I donβt know how to handle environments or package loaders.
I installed Jinja2. These are my simple codes
from jinja2 import Environment, PackageLoader env = Environment(loader=PackageLoader('ap', 'templates')) template = env.get_template('template.html') print template.render(title='hello')
I get this error:
File "a.py", line 3, in <module> env = Environment(loader=PackageLoader('ap', 'templates')) File "/usr/local/lib/python2.7/dist-packages/Jinja2-2.7-py2.7.egg/jinja2/loaders.py", line 214, in __init__ provider = get_provider(package_name) File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 213, in get_provider __import__(moduleOrReq) ImportError: No module named ap
These are my folders.
ap/ __init__.py a.py templates/ template.html
Where am I mistaken? Why am I getting this error "No module named your application"
user1524855
source share