【发布时间】:2021-12-26 20:20:05
【问题描述】:
如何在 html 文件中检查 jinja2 中的特定 URL,然后根据我当前所在的 URL 呈现不同的 html 文件?
例如。
# if {{ request.path == /siteID/ }}
{% include "file1.html" %}
# if {{ request.path == /siteID/abcde/ }}
{% include "file2.html" %}
我觉得目前的逻辑不太好:
<!-- ..... bunch of html lines .... -->
{% if request.path|length > 8 and request.path.startswith('/siteID/') and request.path[8:].strip('/').split('/')|length == 1 %}
{% include "file2.html" %}
{% else %}
{% include "file1.html" %}
{% endif %}
<!-- ..... bunch of html lines .... -->
如果我想在未来做一些事情,我该如何扩展它:
# if {{ request.path == /siteID/abcde/uvwxyz }}
{% include "file3.html" %}
【问题讨论】: