我正在使用Apache mod\u wsgi为django服务。I'v还使用Django-cuser中间件,使用户信息始终可用。我不能真正理解这个中间件是如何工作的。具体源代码:
class CuserMiddleware(object):
@classmethod
def get_user(cls, default=None):
"""
Retrieve user info
"""
return cls.__users.get(threading.current_thread(), default)
@classmethod
def set_user(cls, user):
"""
Store user info
"""
if isinstance(user, str):
user = User.objects.get(username=user)
cls.__users[threading.current_thread()] = user
为什么使用线程。当前线程()作为用户的密钥?如我所知,Apache不会为请求创建不同的thead。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐