2007年09月20日 星期四 23:41
hi,´ó¼ÒºÃ:) ¶¨ÒåÁË__get__, __set__, __delete__ ÕâЩ·½·¨,ÀàµÄʵÀýÈçºÎÖ±½Óµ÷ÓÃÕâЩ·½·¨ÄØ? ¶ø²»ÊÇʹÓÃÀàÀ´µ÷ÓÃ(±ÈÈç: Person.__get__(....) or Person.__set__(....)) -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070920/a1ced1c6/attachment.html
2007年09月21日 星期五 00:40
һʱÏë²»ÆðÀ´__get__ºÍ__set__ÓÃÀ´¸ÉʲôÁË, Ö»¼ÇµÃ__getitem__/__setitem__ÓÃÓÚË÷Òý, __getattr__/__setattr__ÓÃÓÚ×ֶΠ__del__µÄÓ÷¨: del listdemo[index]»òÕßdel dictdemo[key]»òÕßdel instance.fieldname ÔÚ07-9-20£¬ÏôÁ¬Ò <xiaolianyi在gmail.com> дµÀ£º > > hi,´ó¼ÒºÃ:) > > ¶¨ÒåÁË__get__, __set__, __delete__ ÕâЩ·½·¨,ÀàµÄʵÀýÈçºÎÖ±½Óµ÷ÓÃÕâЩ·½·¨ÄØ? > ¶ø²»ÊÇʹÓÃÀàÀ´µ÷ÓÃ(±ÈÈç: Person.__get__(....) or Person.__set__(....)) > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070921/91ee9b80/attachment.html
2007年09月21日 星期五 13:04
ллÐÖµÜ,²»¹ý__delete__ºÍ__del__ÊÇpython¶¨ÒåµÄ²»Í¬·½·¨. ÎÒÏëÖªµÀ__get__,__delete__ ËûÃǵÄÓ÷¨ *.__delete__µÄÎĵµ¼û:http://docs.python.org/ref/descriptors.html ÔÚ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 class AuthenticationMiddleware(object): def process_request(self, request): assert hasattr(request, 'session'), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert ' django.contrib.sessions.middleware.SessionMiddleware'." request.__class__.user = LazyUser() return None request.userÓкܶàÓÐÓõķ½·¨:Èç,request.user.authenticate(), is_authenticated() LazyUser() LazyUserʵÀý»¯Ê±ÊÇÔõôµÃµ½Ò»¸öUser,ËûµÄ»º´æÊÇÔõôʵÏÖµÄÄØ? ÔÚ07-9-21£¬Samuel Chi <princeofdatamining在gmail.com> дµÀ£º > > һʱÏë²»ÆðÀ´__get__ºÍ__set__ÓÃÀ´¸ÉʲôÁË, > Ö»¼ÇµÃ__getitem__/__setitem__ÓÃÓÚË÷Òý, > __getattr__/__setattr__ÓÃÓÚ×ֶΠ> > __del__µÄÓ÷¨: > del listdemo[index]»òÕßdel dictdemo[key]»òÕßdel instance.fieldname -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070921/61fb3a22/attachment.html
2007年09月21日 星期五 17:34
ÔÚÒ»¸öÒ³ÃæÇëÇóÖеÚÒ»´Îµ÷ÓÃrequest.userÊÇ»áµ÷ÓÃget_user£¬¶øºóÀ´ÔÙµ÷ÓÃrequest.user¾Í»áÖ±½Ó¸ø³öÕâ¸öuserÁË ÔÚ07-9-21£¬ÏôÁ¬Ò <xiaolianyi在gmail.com> дµÀ£º > > ллÐÖµÜ,²»¹ý__delete__ºÍ__del__ÊÇpython¶¨ÒåµÄ²»Í¬·½·¨. > ÎÒÏëÖªµÀ__get__,__delete__ ËûÃǵÄÓ÷¨ > *.__delete__µÄÎĵµ¼û:http://docs.python.org/ref/descriptors.html > > ÔÚ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 > > class AuthenticationMiddleware(object): > def process_request(self, request): > assert hasattr(request, 'session'), "The Django authentication > middleware requires session middleware to be installed. Edit your > MIDDLEWARE_CLASSES setting to insert ' > django.contrib.sessions.middleware.SessionMiddleware'." > request.__class__.user = LazyUser() > return None > > request.userÓкܶàÓÐÓõķ½·¨:Èç,request.user.authenticate(), is_authenticated() > > LazyUser() LazyUserʵÀý»¯Ê±ÊÇÔõôµÃµ½Ò»¸öUser,ËûµÄ»º´æÊÇÔõôʵÏÖµÄÄØ? > > ÔÚ07-9-21£¬Samuel Chi <princeofdatamining在gmail.com > дµÀ£º > > > > һʱÏë²»ÆðÀ´__get__ºÍ__set__ÓÃÀ´¸ÉʲôÁË, > > Ö»¼ÇµÃ__getitem__/__setitem__ÓÃÓÚË÷Òý, > > __getattr__/__setattr__ÓÃÓÚ×ֶΠ> > > > __del__µÄÓ÷¨: > > del listdemo[index]»òÕßdel dictdemo[key]»òÕßdel instance.fieldname > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070921/cb2bb3a7/attachment.html
2007年09月24日 星期一 20:16
:) Àí½âÁË,__get__¶¨ÒåÁËÒÔºó,python»áÈ¥×Ô¶¯µ÷ÓÃ,ºÇºÇ,ºÜˬ. request.__class__.user = LazyUser() ²»¹ý»¹ÓÐÒ»¸ö²»Àí½âµÄµØ·½,django¸ÉÂðÒªÓÃÀàµÄÊôÐÔÀ´±£´æuserÄØ?Ϊʲô²»ÓÃʵÀýÄØ? ÔÚ07-9-21£¬leopay <leopay在gmail.com> дµÀ£º > > ÔÚÒ»¸öÒ³ÃæÇëÇóÖеÚÒ»´Îµ÷ÓÃrequest.userÊÇ»áµ÷ÓÃget_user£¬¶øºóÀ´ÔÙµ÷ÓÃrequest.user¾Í»áÖ±½Ó¸ø³öÕâ¸öuserÁË > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070924/fee70559/attachment.html
2007年09月24日 星期一 23:28
²¹Ï°Ï³£Ê¶.mark ÔÚ07-9-24£¬xiao lianyi <xiaolianyi在gmail.com> дµÀ£º > > :) > Àí½âÁË,__get__¶¨ÒåÁËÒÔºó,python»áÈ¥×Ô¶¯µ÷ÓÃ,ºÇºÇ,ºÜˬ. > > request.__class__.user = LazyUser() > ²»¹ý»¹ÓÐÒ»¸ö²»Àí½âµÄµØ·½,django¸ÉÂðÒªÓÃÀàµÄÊôÐÔÀ´±£´æuserÄØ?Ϊʲô²»ÓÃʵÀýÄØ? > > > ÔÚ07-9-21£¬leopay <leopay在gmail.com> дµÀ£º > > > > ÔÚÒ»¸öÒ³ÃæÇëÇóÖеÚÒ»´Îµ÷ÓÃrequest.userÊÇ»áµ÷ÓÃget_user£¬¶øºóÀ´ÔÙµ÷ÓÃrequest.user¾Í»áÖ±½Ó¸ø³öÕâ¸öuserÁË > > > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070924/f509c0dc/attachment.html
Zeuux © 2025
京ICP备05028076号