Re: Request data is lost between two views

2007-10-17 Thread rskm1

On Oct 16, 5:35 am, Divan Roulant <[EMAIL PROTECTED]> wrote:
> I loose request data when I call a view with reverse from a previous
> view. Here is what I do:
>
> def my_first_view(request):
> # Processing here
> return HttpResponseRedirect(reverse('my_second_view,
> args=(request,)))
>
> def my_second_view(request):
> # I would like to processing request data from the previous view,
> but request is empty
> return render_to_response('results.html', ...)

Kinda pointing out the obvious, but the views ARE, after all, just
Python functions.
USUALLY you want to redirect after processing a form, for example, but
maybe in your case you don't?

Note that there are some caveats to doing this (like, what happens if
a user hits [Reload] on the second page, which will still have the
"original" URL), but in your case you might be able to skip all the
reverse-lookups and url evaluation, and simply:

def my_first_view(request):
  # Processing here
  # Don't send a response from here, just pass control to
my_second_view's implementation
  return my_second_view(request, parmsInADict)

def my_second_view(request, parmsFromFirstView=None):
  # also look in the parmsFromFirstView dict, not just request.POST...
  return render_to_response('results.html', ...)

If you MUST redirect in your situation, well nevermind, see the other
responses.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Request data is lost between two views

2007-10-16 Thread Doug Van Horn

On Oct 16, 5:35 am, Divan Roulant <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I loose request data when I call a view with reverse from a previous
> view. Here is what I do:
[snip]
> Is request data supposed to follow or is it normal to loose it? Is
> there another way to preserve request data between consecutive views?

To understand your problem you need to understand what
HttpResponseRedirect() is doing.  When you return that object, your
server sends the browser a 302 status code.  A 302 tells the browser
the desired page can be found under the new (temporary) URL you
specify.  The browser then requests the new URL as a GET.  It does not
resend any GET or POST data sent to the original URL.

If you want to pass some parameters to that second view, you can put
them on the URL you send in your response-redirect.  Something like:

return HttpResponseRedirect("/mysite/secondview/?foo=%(foo)s&bar=%
(bar)s") % request

Or you could store the data in the user session.  Or you could just do
your work in the first view.  ;-)


doug.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Request data is lost between two views

2007-10-16 Thread Thomas Guettler

Am Dienstag, 16. Oktober 2007 12:35 schrieb Divan Roulant:
> Hello,
>
> I loose request data when I call a view with reverse from a previous
> view. Here is what I do:
>... return HttpResponseRedirect(reverse('my_second_view,
> args=(request,)))
> Is request data supposed to follow or is it normal to loose it? Is
> there another way to preserve request data between consecutive views?

Hi,

It is normal that you loose them. This is a HTTP Redirect. The webbrowser
will do a second GET.

You can use from django.utils.http urlencode(request.GET) to build
the new URL.

This will redirect the webbrowser to the new URL with data.

 HTH,
  Thomas

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Request data is lost between two views

2007-10-16 Thread Divan Roulant

Hello,

I loose request data when I call a view with reverse from a previous
view. Here is what I do:

def my_first_view(request):
# Processing here
return HttpResponseRedirect(reverse('my_second_view,
args=(request,)))

def my_second_view(request):
# I would like to processing request data from the previous view,
but request is empty
return render_to_response('results.html', ...)

URLConf:
 (r'^mysite/secondview/$', 'mysite.my_second_view', {},
'my_second_view'),

Is request data supposed to follow or is it normal to loose it? Is
there another way to preserve request data between consecutive views?

Thanks!

Divan


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---