I am trying to use this package without using any specific framework, and I am trying to create a template for a markdown file. Everything works fine when using a file as a template, but when using the include function within the template to call another file, it is giving me the error: jinja2.exceptions.TemplateNotFound
Template Code
template.md
# This is Markdown file
{%ifa == True%}{%include'./a.md'%}{%else%}{%include'./b.md'%}{%endif%}
"""
a.md
this is a.md
b.md
this is b.md
example.py
from jinja2 import Environment, BaseLoader
with open('./template.md', 'r') as reader:
file = reader.read()
template = Environment(loader=BaseLoader()).from_string(file)
render = template.render({"a": True})
Full Traceback
File "example.py", line 7, in <module>
render = template.render({"a": True})
File ".virtualenvs/cv3/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in renderreturn original_render(self, *args, **kwargs)
File ".virtualenvs/cv3/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in renderreturnself.environment.handle_exception(exc_info, True)
File ".virtualenvs/cv3/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File ".virtualenvs/cv3/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraiseraise value.with_traceback(tb)
File "<template>", line 4, in top-level template code
File ".virtualenvs/cv3/lib/python3.6/site-packages/jinja2/loaders.py", line 91, in get_sourceraise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: a.md
Environment
Python version: Python 3.6.0
Jinja version: 2.10
The text was updated successfully, but these errors were encountered:
You need to use a FileSystemLoader (or any other loader that actually knows how to load a template given a name) if you want to reference other templates.
Also, please use IRC or Stack Overflow for this kind of question.
I am trying to use this package without using any specific framework, and I am trying to create a template for a markdown file. Everything works fine when using a file as a template, but when using the
includefunction within the template to call another file, it is giving me the error: jinja2.exceptions.TemplateNotFoundTemplate Code
template.md
a.md
b.md
example.py
Full Traceback
Environment
The text was updated successfully, but these errors were encountered: