Skip to content
Advertisement

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.

Advertisement

Answer

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

6 People found this is helpful
Advertisement