I have a views.py
file that has the following method:
def alterar(request, pk):
cliente = get_object_or_404(Cliente, pk=pk)
if request.method == 'POST':
form = ClienteForm(request.POST, instance = cliente)
if form.is_valid():
cliente = form.save(commit=False)
cliente.save()
cliente_listar = Cliente.objects.all()
return render(request, 'cliente/listar.html', {'cliente' : cliente_listar})
else:
form = ClienteForm(instance=cliente)
return render(request, 'cliente/cadastro.html', {'form' : form})
My problem is in render()
of POST
, because returning url from list still has the following url : http://127.0.0.1:8000/cliente/alterar/5/
, but with the list page , the right one for me would have to be: http://127.0.0.1:8000/cliente/listar/
.
In some searches I found redirect()
but equal to url is in this format: http://127.0.0.1:8000/cliente/alterar/5/cliente/listar.html
where it ends up giving error.
I'm using Python 3.5 and Django 1.10