Sessions living through HttpResponseRedirect

394 views
Skip to first unread message

Joshua K

unread,
Mar 31, 2009, 10:47:17 PM3/31/09
to Django users, jo...@globalherald.net
Howdy Folks,

How do I get a session to live through a HttpResponseRedirect? For
example:

form = clientFormCreate(request.POST)
if form.is_valid():
newClient = form.save()
request.sesson['current_client'] = str(newClient.pk)
return HttpResponseRedirect('/clients/')

I was under the impression that I had to re-create a context from the
modified request object, then render the context - but you can't
render a context with HttpResponseRedirect.

Thanks!
-Josh

Daniel Roseman

unread,
Apr 1, 2009, 2:39:00 AM4/1/09
to Django users
On Apr 1, 3:47 am, Joshua K <jobe...@gmail.com> wrote:
> Howdy Folks,
>
> How do I get a session to live through a HttpResponseRedirect?  For
> example:
>
>         form = clientFormCreate(request.POST)
>         if form.is_valid():
>             newClient = form.save()
>             request.sesson['current_client'] = str(newClient.pk)
>             return HttpResponseRedirect('/clients/')

Does this not work? It should. What happens when you try?

> I was under the impression that I had to re-create a context from the
> modified request object, then render the context - but you can't
> render a context with HttpResponseRedirect.

Sessions have nothing to do with contexts.
--
DR.

Bro

unread,
Apr 1, 2009, 5:44:24 AM4/1/09
to Django users
Hi Josh,

I think the best is after you create a client,
he should log in.

When the client log in, you can use : request.user
to get user information.

Good luck
Bro

Joshua K

unread,
Apr 1, 2009, 3:09:36 PM4/1/09
to Django users
Daniel, thanks for the note - I found out that it does work as I
expected.

Bro, thanks for the hint - but in this case a 'client' is not the same
person who is logged in.

sspross

unread,
Apr 24, 2012, 3:31:39 AM4/24/12
to django...@googlegroups.com, jo...@globalherald.net
Hi Joshua

What was your solution here? It looks like I'm having the same kind of problem like you:


Thx!

Regards,
Silvan

Alexandr Aibulatov

unread,
Apr 24, 2012, 3:48:31 AM4/24/12
to django...@googlegroups.com
Set request.session.modified = True

2012/4/24 sspross <spr...@allink.ch>:

> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/3DrUy8ckwDYJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

Reply all
Reply to author
Forward
0 new messages