0

I'm trying to use jinja2 as template for a xml-like language.

The code below, is a example of this language with a jinja2 base template. This template calls a child one.

Base Template:

<?xml version="1.0" encoding="UTF-8"?> 
<!-- An NCL SlideShow example with embedded Jinja2 template -->
<ncl id="slideShow">
    <head>
        <connectorBase>
            <importBase documentURI="connectorBase.ncl" alias="conBase"/>
        </connectorBase>
        <regionBase>
            <region id="main" width="100%" height="100%" zIndex="1"/>
        </regionBase>
        <descriptorBase>
            <descriptor id="ImageDes" region="main"/>
        </descriptorBase>
    </head>
    <body>
        <port id="startSlideShow" component="image1"/>
        {% block medias %}
        {% endblock %}
    </body>
</ncl>

Child Template:

{% extends "slide_show.j2.ncl" %}
{% block media %}
    <media id="image1" src="media/WinterSun.jpg" 
descriptor="ImageDes"/> 
{% endblock media %}

From a python code, I try to load base template file.

if __name__ == "__main__":
    env = Environment(
        loader=FileSystemLoader('/templates/slide_show.j2'),
        autoescape=select_autoescape(['ncl', 'xml'])
    )

    template = env.get_template('slide_show.j2')

However, I get this exception below:

jinja2.exceptions.TemplateNotFound: slide_show.j2

1 Answer 1

0

Found out that FyleSystemLoader should receives full path to folder, not a relative. Their documentation doesn't make it clear.

loader = FileSystemLoader('fullpath/to/file')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.