render_to_response and HttpResponseRedirect

36 views
Skip to first unread message

elcaiaimar

unread,
Mar 11, 2015, 6:21:34 AM3/11/15
to django...@googlegroups.com
Hello!

I'm having problems in a form. I want to send some values with it to 'obras/edicionobra.html' but I also want to redirect to the page "/edicionobra/". In the code below I send the values and I go to edicionobra.html, however, the URL is /nuevacuenca/ and that's wrong.

I've tried to put HttpResponseRedirect("/edicionobra/") at the end of the form, but then I don't send the values

How can I solve my problem?
def NuevaCuenca(request):
   
if not request.user.is_authenticated():
       
return HttpResponseRedirect('/')

    idobra
=request.POST['obra']
    lobras
= Obra.objects.filter(id=idobra)
    obra
=lobras[0]
    cuencas
= CuencasObra(request)
   
if "nuevacuenca" in request.POST:
        formulario
= CuencasForm(request.POST)
       
if formulario.is_valid():
            titulo
= 'Formulario de cuenca'
   
            dc
=request.POST['descripcion_cuenca']
            idobra
=request.POST['obra']

            cuenca
=Cuenca(gid_obra_id=idobra, descripcion_cuenca=dc)            
            cuenca
.save()

           
return render_to_response('obras/edicionobra.html', {'idobra':idobra, 'obra':obra, 'cuencas':cuencas}, context_instance=RequestContext(request))
   
else:
        formulario
= CuencasForm()
   
return render_to_response('cuencas/nuevacuenca.html',{'formulario':formulario, 'idobra':idobra, 'obra':obra}, context_instance=RequestContext(request))


elcaiaimar

unread,
Mar 11, 2015, 9:56:11 AM3/11/15
to django...@googlegroups.com
Finally, I've changed my way to send parameters, it's much better send them by url.
Reply all
Reply to author
Forward
0 new messages