> How can I add an attribute or variable? to the request object in > middleware, where I can use it in other views via the request object.
You can use threading.local() variables, like this: import threading _thread_locals = threading.local() def get_current_user(): return getattr(_thread_locals, 'user', None) class ThreadLocals(object): """Middleware that gets various objects from the request object and saves them in thread local storage.""" def process_request(self, request): _thread_locals.user = getattr(request, 'user', None) In this example, I get "user" variable from "request" object and add it to the "_thread_locals" object. After that I can use get_current_user() function for getting saved variable any time. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---