Django form without using django form


I have a form prepared without using the form of django (It was one of the requirements that they demanded, not using the django form). I use this form to create and edit. The form creates and edits perfectly, but I find an error (I call it that) because in the url when editing, I continue to load the client's id. How do I clean that URL?

this is the view

def clientes_editar(request, id_cliente):
    cliente = Cliente.objects.get(id = id_cliente)
    if request.method == 'GET': #para q cargue los datos en el template
        return render(request,'estructuracion/cliente_crear.html')
    if request.method == 'POST':#para guardar los datos una vez modificados
            cliente.nombre = request.POST['nombre']
            cliente.documento = request.POST['numero_documento']
   = request.POST['email']
            cliente.ciudad = Ciudad.objects.get(pk = request.POST['ciudad'])

    return render(request,'estructuracion/cliente_consultar.html')

URL link

URL after editing link

I would like the url to stay like this link

url(r'^clientes$', clientes_create, name='clientes'),
url(r'^clienteseditar/(?P<id_cliente>\d+)/$', clientes_editar, name='clientes_editar'),
url(r'^clientesConsultar$', clientes_consultar,name='clientes_consultar'),
asked by jhon1946 27.11.2016 в 23:35

1 answer


What I see is that you are simply changing the template, but you are not redirecting to another view, this is basically what you should do, once you create your client with the data of the "form", you should send it to another view that points to another url, otherwise, as you are doing, load another template, but with the same url, a serious example ...

return redirect('consultar_cliente')  # en caso que tenga nombre la url
return HttpResponseRedirect('/estructuracion/clientesConsultar')  # en el caso contrario

and that url must point to another view, that view in turn must return the template you want to show in this case I guess it would be return render(request,'estructuracion/cliente_consultar.html') and ready, so you manage each logic of each page independently and orderly, I hope I have helped you, any doubt comments

answered by 28.11.2016 / 14:25