2007年05月15日 星期二 18:16
django.contrib.auth.middleware.pyÖÐ class LazyUser(object): def __get__(self, request, obj_type=None): if not hasattr(request, '_cached_user'): from django.contrib.auth import get_user request._cached_user = get_user(request) return request._cached_user Õâ¸ö__get__º¯ÊýµÄ²ÎÊýrequestÊÇÔõÑù´«µÝ½øÈ¥µÄ£¿ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070515/074a5037/attachment.html
2007年05月15日 星期二 18:28
On 5/15/07, leopay <leopay在gmail.com> wrote: > django.contrib.auth.middleware.py中 > > > class LazyUser(object): > def __get__(self, request, obj_type=None): > if not hasattr(request, '_cached_user'): > from django.contrib.auth import get_user > request._cached_user = get_user(request) > return request._cached_user > > > 这个__get__函数的参数request是怎样传递进去的? 是由django的server调度程序调用和传递的。参见django/core/handlers/ base.py -- I like python! UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad My Blog: http://www.donews.net/limodou
2007年05月15日 星期二 19:39
On 5/15/07, leopay <leopay at gmail.com> wrote: > > django.contrib.auth.middleware.py中 > > > class LazyUser(object): > def __get__(self, request, obj_type=None): > if not hasattr(request, '_cached_user'): > from django.contrib.auth import get_user > request._cached_user = get_user(request) > return request._cached_user > > > 这个__get__函数的参数request是怎样传递进去的? > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese 把 descriptor 附给 request 的 class 对象, request.__class__.user = LazyUser() 随后访问 request.user 就等价于: request.__class__.user.__get__(request, request.__class__) 就是这么传进去的。 -- http://codeplayer.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20070515/76af25b9/attachment.html
Zeuux © 2025
京ICP备05028076号