python - 如何在 Django 模板页面中设置 href
问题描述
我对 Django 很陌生。我的主页模板如下所示:
{% block content %}
{% for link in embededLinks %}
<div class="row justify-content-center">
<blockquote class="twitter-tweet">
<p lang="en" dir="ltr">Do you get the impression that the Supreme Court doesn’t like me?</p>
— Donald J. Trump (@realDonaldTrump)
<a href="{{%link%}}">June 18, 2020</a>
</blockquote>
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
</div>
{% endfor %}
{% endblock %}
该循环遍历我的网站的链接列表,以正确显示嵌入的推文。这个 html 将放在我拥有的基本模板中。唯一的问题是我在这一行得到一个错误:
<a href="{{%link%}}">June 18, 2020</a>
href 链接在另一个 python 文件中生成,类型为 str。唯一的问题是我不确定如何使用 Django 设置 href。
解决方案
我没有 Django 经验,但我使用 Flask。
会不会是显示一个变量{{ link }}
而不是{{%link%}}
?
推荐阅读
- regex - 添加用户代理过滤器后,codeigniter .htaccess 文件无法访问 css 和 js 文件,给出 404
- postgresql - 如何在 PostgreSQL 中使用相似的列连接两个表并将不匹配的字段保留为 NULL 或保持不变
- powershell - 无法加载文件或程序集 - Powershell
- r - 将 `emmeans::joint_tests()` 输出中的 p 值格式保留在针织 pdf 中
- r - macOS 上 R 中的 BLAS 设置
- scala - 使用 circe 过滤结果 JSON
- java - 实例化作业 Quartz 时出现异常
- c - vlsi 放置中的单元格重叠去除
- postgresql - 加快 Postgres 中的 autovacuum
- javascript - 以 d3 惯用方式插入基于子属性的 d3 元素