python - Flask 比较字符串

如果我将文件上传到我的 flask 脚本但我不喜欢它,我将文件名设置为“无”以便它显示默认图像。然后,在我的 Flask 模板中,我想测试文件名是否为“None”;如果是这样,显示默认值。否则,显示文件。这是我的模板代码,它不起作用:

<!doctype html>
<title>Hello from Flask</title>
{% if {{filename}} is "None" %}:
  <h1>some text<img src="{{filename}}"> more text!</h1>
{% else %}
  <h1>Impossible file: here is tha default so<img src="MB.png"> boi</h1>
{% endif %}

我认为问题出在字符串比较上。我想我不知道如何正确比较字符串。

谢谢!

最佳答案

这个呢?

{% if filename == "None" %}

{% %} 中不需要双括号

例如:https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#operator

https://stackoverflow.com/questions/42167911/

相关文章:

ruby - 安装 jekyll-admin 到 github pages 托管的 jekyll 站

sql - 主键和标识有什么区别?

three.js - 围绕轨道旋转对象

xcode - 如何点击 tvOS 模拟器中的选项卡?

python-3.x - Python 3 inside Sublime Text with Ana

php - 如何从还包含整数的字符串中仅提取 float (小数)

php - 使用 Carbon PHP 格式化日期

html - 将所有 UL LI 元素对齐在一行中并仅将 CSS 应用于 UL?

c# - WinForms 列标题 FontStyle

python - 如何在 Python 中将 unicode 字符串加载到 json 中?