On Wed, 2006-10-18 at 11:32 +0000, orestis wrote: > OK, I'm having a silly problem: > > In one view I set a property in the user's session. > Then, in the template returned by the same view, a custom template tag > queries the database Session objects and displays a message depending > on the property set before. > > However, this doesn't work the first time. Only after the second time > does the template tag "get" the modified session. > > I would like the processing to happen in the following order: > > request -> my view modifies session -> session is saved in the db -> my > template tag reads sessions -> render response > > However, I imagine that the order is like this: > > request -> my view modifies session -> my template tag reads sessions > -> render response -> session is saved in the db
This is correct. The session is only saved as part of the response middleware, which happens after your view function returns (and the template is rendered as part of your view function). > > And this is why it works the second time round. Is there any way I can > call save() on the session explicitly ? Have a look in django/contrib/sessions/middleware.py (in the SessionMiddleware.process_response() method). There you can see how Django saves the session. You need to emulate some of that logic. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---

