[Python] Jinja2 {% include file %} outside of search path doesn't work

Discussão em 'Python' iniciado por Stack, Março 6, 2025.

  1. Stack

    Stack Membro Participativo

    This is an elementary issue which is probably related to Jinja2 PrefixLoader or ChoiceLoader.

    On Python 3.6 we load with this command

    jinja2.FileSystemLoader( searchpath= "\\template_folder\\")


    On Windows 7, our file structure is as follows.


    - folder_bbb
    * subfile.txt
    - template_folder
    * template_file
    - folder_aaa
    * subfile.txt


    From the template_file we are successful with this command

    {% include "folder_aaa/subfile.txt" %}


    Now we wish to move the file one level up, and write

    {% include "../folder_bbb/subfile.txt" %}


    but that doesn't work, complaining file not found.

    What is the correct way to write? Thanks.

    Continue reading...

Compartilhe esta Página