1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to get and pass selected id to modal?

Discussão em 'Python' iniciado por Stack, Setembro 15, 2024.

  1. Stack

    Stack Membro Participativo

    I'm new to python/flask and I have a table with users in it that contains a delete button next to each user in the table. How do I get the userId of the selected user, so that I can pass it to my confirmation modal for deletion?

    Here's a snippet of what I currently have and tried, but the set isn't working like I thought it would.

    <table class="table align-middle table-striped table-bordered table-sm table-responsive">
    <thead>
    <tr class="table-dark">
    <th>Action</th>
    <th>User</th>
    <th>Email</th>
    </tr>
    </thead>
    <tbody>

    {% for admin in admin_users %}
    <tr>
    <td id="action">
    <button type="button" class="btn btn-block btn-danger btn-sm" data-bs-toggle="modal" data-bs-target="#deleteModal">Delete</button>
    </td>
    <td>{% set admin_id = admin.id %} {{ admin.username }}</td>
    <td>{{ admin.email }}</td>
    </tr>
    {% endfor %}
    </tbody>
    </table>


    <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
    <form action="{{ url_for('delete_user', user_id=admin_id) }}" method="POST">
    <input type="submit" class="btn btn-danger btn-sm" value="Delete">
    </form>
    </div>

    Continue reading...

Compartilhe esta Página