开发者

How to know the 'controller' and 'action' from the request url?

开发者 https://www.devze.com 2023-01-15 13:42 出处:网络
I want to log the controller and action when a request comes, so I write a __before__ in the base controller:

I want to log the controller and action when a request comes, so I write a __before__ in the base controller:

开发者_如何转开发 class BaseController:
     __before__(self):
          controller = get_controller(request)
          action = get_action(request)
          logger.log('%s - %s'%(controller, action))

But I don't know how to get the controller and action just from the request


 params = request.environ['pylons.routes_dict']
 print dir(params)
 #-> {'action':u'action', 'controller':u'controller'}
0

精彩评论

暂无评论...
验证码 换一张
取 消