在django.contrib.auth公司中间件 我看到了密码:
class AuthenticationMiddleware(object):
def process_request(self, request):
assert hasattr(request, 'session'), "requires session middleware"
request.__class__.user = LazyUser()
return None
请告诉我为什么要这样的表格 请求。classclass\user=LazyUser() 用过吗? 为什么不只是 请求.用户=懒人() ? 在
我知道class属性意味着什么,但正如我理解的那样,直接赋值给实例变量会更好。我哪里错了?在
这将影响}实例化后进行更改。在
request
s的创建方式。所有这样的实例都将有它们的user
属性作为特定的LazuUser
,而不需要在每个{LazyUser
是描述符类。根据documentation它只能是类属性而不是实例一:相关问题 更多 >
编程相关推荐