gpt4 book ai didi

python - Pylons - 如何获取当前 Controller 和 Action (当前路线)?

转载 作者:太空狗 更新时间:2023-10-30 02:35:17 25 4
gpt4 key购买 nike

我在 Mako 模板中,我想知道(当前页面的)当前 Controller 和操作是什么。我怎样才能做到这一点?我尝试了 c.controller 和 c.action,但没有用。我还列出了上下文对象的键,但没有找到。

作为解决方法,我一直在每个 Controller 方法中设置 c.controller 和 c.action,但我知道一定有更好的方法。

class MainController(BaseController):

def index(self):
c.controller, c.action = 'main', 'index'
return render("/main.html")

最佳答案

在模板中:

当前网址:

${url.current()}

Controller 和 Action :

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

关于python - Pylons - 如何获取当前 Controller 和 Action (当前路线)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3695107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com