0
Follow
0
View

{% for %} and {% url %} cannot be used together

dengwei99 注册会员
2023-02-28 17:32

This answer references ChatGPT
The problem is that your url tag has another template tag nested inside it, which causes Django to not parse the url you're trying to access properly. You can use the following method to solve this problem:


{% 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 %}


Here, we remove the extra double parentheses and quotes from the url tag and pass vo.name directly as the argument. This will allow Django to correctly parse the url you are trying to access.

About the Author

Question Info

Publish Time
2023-02-28 17:32
Update Time
2023-02-28 17:32