小编Rit*_*vda的帖子

如何检查系统中是否存在文件或在 html 页面中不使用 jinja?

我想检查我的dummy.csv是否存在于我的本地系统中。如果存在,则将显示此检查欺诈状态,否则不会显示。我不想使用 JavaScript。如果有任何与 python jinja有关的解决方案,请帮助我。

还有一件事如何import os在 html 页面中使用 jinja?

我曾尝试过这个:

布局.html

{% if os.path.exists('./static/userdata/dummy.csv') %}
   <a class="nav-item nav-link" href="{{ url_for('checkfraudstatus') }}">Check Fraud Status</a>
{% endif %}
Run Code Online (Sandbox Code Playgroud)

错误

jinja2.exceptions.UndefinedError: 'os' is undefined
Run Code Online (Sandbox Code Playgroud)

html python jinja2 python-3.x

7
推荐指数
1
解决办法
4996
查看次数

标签 统计

html ×1

jinja2 ×1

python ×1

python-3.x ×1