Re: Global variable during request
On Oct 22, 5:35 pm, Jopwrote: > Hello all, > > I've been googeling for a while but haven't been able to find a > solution for my problem. I will try to describe the problem > > I want to be able to set a variable in a view function on the start of > the request. During the same request i want to use the variables value > in a manager method. > > Originally I thought about using a session because I can import the > session object anywhere, but I want the value to be reset after the > request is closed. I also though about trying to define a 'setting' > during runtime, though this seems to be -not done-. > > I have the feeling there must be a real simple solution, but I can't > seem to figure it out. > > Any ideas? > > Thanx a lot! > > Jop Use a middleware class to set the attribute on the request object, then pass that into the manage method from the view when you need to. -- DR. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Global variable during request
Thnx, i'll try that :) On 22 okt, 18:39, Michaelwrote: > Use middleware to set a threadlocal variable in a global namespace on > request, and unset it on response. > -- > Michael > > > > On Fri, 2010-10-22 at 09:35 -0700, Jop wrote: > > Hello all, > > > I've been googeling for a while but haven't been able to find a > > solution for my problem. I will try to describe the problem > > > I want to be able to set a variable in a view function on the start of > > the request. During the same request i want to use the variables value > > in a manager method. > > > Originally I thought about using a session because I can import the > > session object anywhere, but I want the value to be reset after the > > request is closed. I also though about trying to define a 'setting' > > during runtime, though this seems to be -not done-. > > > I have the feeling there must be a real simple solution, but I can't > > seem to figure it out. > > > Any ideas? > > > Thanx a lot! > > > Jop -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Global variable during request
Use middleware to set a threadlocal variable in a global namespace on request, and unset it on response. -- MichaelOn Fri, 2010-10-22 at 09:35 -0700, Jop wrote: > Hello all, > > I've been googeling for a while but haven't been able to find a > solution for my problem. I will try to describe the problem > > I want to be able to set a variable in a view function on the start of > the request. During the same request i want to use the variables value > in a manager method. > > Originally I thought about using a session because I can import the > session object anywhere, but I want the value to be reset after the > request is closed. I also though about trying to define a 'setting' > during runtime, though this seems to be -not done-. > > I have the feeling there must be a real simple solution, but I can't > seem to figure it out. > > Any ideas? > > Thanx a lot! > > Jop > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Global variable during request
Hello all, I've been googeling for a while but haven't been able to find a solution for my problem. I will try to describe the problem I want to be able to set a variable in a view function on the start of the request. During the same request i want to use the variables value in a manager method. Originally I thought about using a session because I can import the session object anywhere, but I want the value to be reset after the request is closed. I also though about trying to define a 'setting' during runtime, though this seems to be -not done-. I have the feeling there must be a real simple solution, but I can't seem to figure it out. Any ideas? Thanx a lot! Jop -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.