Hi, I have a question to using threadlocals trick on Apache/mod_wsgi. I built some SMS using threadlocals trick and FAILED. I was filtering blog post with current user, and blog post has publish policy like "public"(everyone can see) and "grouped"(user who joined in the group which author joined in can see). Everything was fine on development but deploy. User RANDOMLY can see the post which he/see should be able to see.
what I wrote was like below: ------------------------------------------------------------------------------------------------- # middleware/threadlocals.py from django.utils.thread_support import currentThread _requests = {} def get_request(): if currentThread() in _request: return _requests[currentThread()] return None # Middleware which set request to _requests[currentThread] # ... # blogs/models.py class EntryManager(models.Manager): def published(self): user = threadlocals.get_request().user return self.filter(author=user) class Entry(models.Model): author = models.ForeignKey(User) ------------------------------------------------------------------------------------------------- the threadlocals is copied from some snippets (i forgot which) so i wasn't sure what's happen. now i notice that this threadlocals trick required that Django process has to be unique for each request (to make sure currentThread is unique for each request in the process) isn't it? So I wonder that is Apache/mod_wsgi create new Django process for each request? If so why the code above didn't work proper? and why a lot's of people disagree with `threadlocals` trick even Django (django.db.transaction.py) and django-cms (middleware/user.py) using similar trick? sorry for my ugly English, thank you for reading. P.S. Actually I solved this problem with writing whole custom db.model, forms, generic view which pass `request` to the db.model.save, clean, delete method. However now i wonder how can i change a template loading directory depend on request (for PC, iPhone, mobile...) and using django-cms. so i wonder is there any special settings for mod_wsgi to using threadlocals trick or whatever. any idea is welcome. -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.