{% for %} 和{% url %} 无法一起使用

{% for %} 和{% url %} 无法一起使用
因为我使用{% for %}批量导入了数据,然后我又想给每个数据设置一个跳转页面,路由是设成了list里面的name,但是{% url '{{vo.name}}’ %}好像并不可以,所以想问一下该怎么弄。
                {% for vo in buildinglist %}
                    <div class="col-lg-4 col-sm-6 layout-item-wrap">
                    <article class="property layout-item clearfix">
                    <figure class="feature-image">
                        <a class="clearfix zoom" href="{% url "{{ vo.name }}" %}"><img data-action="zoom" 
                          src="/static/uploads/building/{{ vo.cover_pic }}" alt="">a>
                    figure>
                    <div class="property-contents clearfix">
                    <header class="property-header clearfix">
                        <div class="pull-left">
                            <h6 class="entry-title"><a href="{% url "{{ vo.name }}" %}">{{ vo.name }}a>h6>
                            <span class="property-location"><i class="fa fa-map-marker">i> {{ vo.address }}span>
                        div>
                    header>
                    div>
                    article>
                    div>
                {% endfor %}
             
Reverse for '{{ vo.name }}' not found. '{{ vo.name }}' is not a valid view function or pattern name.

该回答引用ChatGPT
问题在于您的url标签中嵌套了另一个模板标签,这会导致Django无法正确解析您要访问的url。您可以使用以下方法来解决此问题:


{% for vo in buildinglist %}
    <div class="col-lg-4 col-sm-6 layout-item-wrap">
    <article class="property layout-item clearfix">
    <figure class="feature-image">
        <a class="clearfix zoom" href="{% url vo.name %}"><img data-action="zoom" 
          src="/static/uploads/building/{{ vo.cover_pic }}" alt=""></a>
    </figure>
    <div class="property-contents clearfix">
    <header class="property-header clearfix">
        <div class="pull-left">
            <h6 class="entry-title"><a href="{% url vo.name %}">{{ vo.name }}</a></h6>
            <span class="property-location"><i class="fa fa-map-marker"></i> {{ vo.address }}</span>
        </div>
    </header>
    </div>
    </article>
    </div>
{% endfor %}


在这里,我们从url标签中删除了额外的双括号和引号,并直接传递了vo.name作为参数。这将使Django正确解析您要访问的url。