Create dialog in Django

Asked

Viewed 133 times

1

I am trying to create a dialog to remove a client in Django (I created the dialog with Materialize), but when trying to remove it does not execute the view function inside the html page. Could someone help?inserir a descrição da imagem aqui

delete

        <!-- Modal Structure -->
        <div id="modal1" class="modal">
            <div class="modal-content">
                <h4>Deseja remover o Cliente {{ Cliente.nome_cliente }}?</h4>
            </div>
            <div class="modal-footer">
                <form method="post">
                    {% csrf_token %}
                    <button name="remover_cliente" type="submit" class="modal-close btn light-blue lighten">Remover</button>
                    <a href="{% url 'listar_cliente' %}" class="modal-close btn light-blue lighten">Voltar</a>
                </form>
            </div>
        </div>

Views.py

@login_required
def remover_cliente(request, pk):
    cliente = Cliente.objects.get(pk=pk)
    if request.method == "POST":
        cliente.delete()
        return redirect('listar_cliente')
    return render(request, {'cliente': cliente})
  • I thought about it but I didn’t know if it was right. Now I know how to do it, thank you.

1 answer

0

Your form is not invoking the view, then it does not perform the task. You forgot to put the action="{% url 'remover_cliente' %}" within the tag form.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.