python - 使用 jinja 标签在 html 标签内使用 if 条件
问题描述
我为我的站点项目制作了一个标题,它有一些部分......我想使用 jinja 更改标题上的部分颜色名称,但我不能没有错误地呈现模板,但部分名称不会改变,并且在 pycharm 中消息显示:标签开始未关闭
<ul class='menu'>
<li {% if section == "dashboard" %}class="selected"{% endif %}>
<a href="{% url 'dashboard' %}">My dashboard</a>
</li>
<li {% if section == "images" %}class="selected"{% endif %}>
<a href="#">Images</a>
</li>
<li {% if section == "people" %}class="selected"{% endif %}>
<a href="#">People</a>
</li>
</ul>
解决方案
<ul class='menu'>
<li class="selected">
{% if section == "dashboard" %}
<a href="{% url 'dashboard' %}">My dashboard</a>
{% elif section == "images" %}
<a href="#">Images</a>
{% elif section == "people" %}
<a href="#">People</a>
{% endif %}
</li>
</ul>
推荐阅读
- sas - 如何在SAS中将两列合并为一列
- azure - Azure 视频索引器下载网址
- rust - 当我们向变量添加新所有权时,旧所有权会发生什么?
- android - 如何在 FirebaseRecyclerAdapter 中添加项目 OnClickListener?
- javascript - 图像不跨越多个表列 docxjs
- java - Android Java Caller-Overlay (Info-PopUp)
- javascript - 简单组件不会出现在浏览器上
- python - 即使安装了模块,执行 shell 脚本后也找不到 python 模块
- ios - 通过可编码协议管理动态密钥以响应
- python-3.x - PC 上的 TensorFlow 对象检测 API