Pylons - How to get the current controller and action (current route)?
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']}
精彩评论