我想根据一个变量指向不同的HTML文件。我正在使用以下格式的include:
{% include 'templates/case/{{cid}}/intro.html' %}
这会抛出一个错误:
TemplateNotFound: templates/case/{{cid}}/intro.html
从这个例子中可以看出,Jinja2并不会在运行时解析变量。变量cid = ABC
(ABC是路径中某个文件夹的名称),因此我期望的完整路径是:
Looking at this I know Jinja2 does not resolve the variable at runtime. The value of cid = ABC
(ABC is a folder's name in the path), so I expected the total path to be:
templates/case/ABC/intro.html
如果我直接在include中使用这个解析后的路径,它就能工作。
我该如何解决这个问题?