开发者

Pylons - How to get the current controller and action (current route)?

开发者 https://www.devze.com 2023-01-16 00:57 出处:网络
I\'m in a Mako template, and I want to know what the current controller and action is (of the current page). How can I do this? I tried c.controller and c.action, but it didn\'t work. I also listed th

I'm in a Mako template, and I want to know what the current controller and action is (of the current page). How can I do this? I tried c.controller and c.action, but it didn't work. I also listed the keys of the context object but didn't find it.

As a workaround, I've been setting c.controller and c.action from within each controller method, but I know there must be a better way.

class MainController(BaseController):

    def index(self):
        c.controller, c.action = 'main', 'index'
        return render("/ma开发者_开发百科in.html")


In a template:

Current url:

${url.current()}

Controller and action:

${url.environ['pylons.routes_dict']['controller']}
${url.environ['pylons.routes_dict']['action']}
0

精彩评论

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