首页 > 解决方案 > 如何在 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>
            &mdash; 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。

标签: pythondjangoweb-applications

解决方案


我没有 Django 经验,但我使用 Flask。

会不会是显示一个变量{{ link }}而不是{{%link%}}


推荐阅读