Janson
Janson

Reputation: 89

Setting href to dynamic view name

 {% for stg in statusUrl %}
            <tr>
                <td>{{forloop.counter}}</td>
                <td>{{stg.title}}</td>
                <td>
                  <a href="{% url {{stg.addLink}} %}" class="btn text-secondary px-0">
                    <i class="fas fa-plus"></i></a>
                   </a>
                

                  <a href="{% url {{stg.editLink}} invoice.id %}" class="btn text-secondary px-0">
                      <i class="fa fa-edit fa-lg"></i>
                    </a> 

                  <a href="{% url {{stg.deleteLink}} invoice.id %}" class="btn text-secondary px-0">
                      <i class="far fa-trash-alt fa-lg text-danger float-right"></i>
                   </a> 

                  <a href="{% url {{stg.previewLink}} invoice.id %}" class="btn text-secondary px-0">
                      <i class="fas fa-file-invoice"></i>
                   </a>
                </td>
            </tr>
            {% endfor %}

Trying to pass urls.py view names dynamically to template and then creating hyperlink to each view. How can href be adjusted to handle it.

Upvotes: 0

Views: 44

Answers (1)

Elvin Jafarov
Elvin Jafarov

Reputation: 1456

I do not know what stg.addLink returns but to make it work you need to change

from


"{% url {{stg.editLink}} invoice.id %}"

to


"{% url stg.editLink invoice.id %}"

BUT AGAIN it may not work. It depents what stg.editLink returns

Upvotes: 1

Related Questions