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
datos={'nombre':cliente.nombre,'numero_documento':cliente.documento,\
'email':cliente.email,'ciudad':cliente.ciudad}
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']
cliente.email = request.POST['email']
cliente.ciudad = Ciudad.objects.get(pk = request.POST['ciudad'])
cliente.save()
return render(request,'estructuracion/cliente_consultar.html')
URL link
URL after editing link
I would like the url to stay like this link
url.py
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'),