tags:

views:

65

answers:

1

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("/main.html")
+2  A: 

In a template:

Current url:

${url.current()}

Controller and action:

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