[Django]-How do i make a functioning Delete confirmation popup in Django using Bootstrap4 Modal

0👍

Try this.

<!-- Modal -->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            ...
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <a class="btn btn-sm btn-danger" href="{% url 'delete_order' order.id %}">Delete</a>
          </div>
        </div>
      </div>
    </div>
<table class="table table-sm">
    <tr>
        <th>Product</th>
        <th>Date Ordered</th>
        <th>Status</th>
        <th>Update</th>
        <th>Delete</th>
    </tr>

    {% for order in orders %}
    <tr>
        <td>{{ order.product }}</td>
        <td>{{ order.date_created }}</td>
        <td>{{ order.status }}</td>
        <td><a class="btn btn-sm btn-info" href="{% url 'update_order' order.id %}">Update</a></td>
        <td><a class="btn btn-sm btn-danger" href="#" data-toggle="modal" data-target="#exampleModal">Delete</a></td>
    </tr>
    {% endfor %}

</table>

— UPDATE —
url.py, most common use is urls.py
Your pk should to be int not str

urlpatterns = [
    path('delete_order/<int:pk>', views.deleteOrder, name="delete_order"),
]

Leave a comment