Plon 4:将参数传递给视图类(BrowserView)

发布于 2024-12-29 18:23:42 字数 847 浏览 0 评论 0原文

我一直在关注此网址来帮助我创建使用 BrowserView 的模板视图。到目前为止,它工作正常,我能够创建带有视图类的模板。

我需要知道的是是否可以将参数传递给视图类内部的方法,即

from Products.Five import BrowserView

class Html(BrowserView):
    def still_dreaming(self):
        msg = "Some people are still dreaming"
        return msg

我需要向 still_dreaming 函数添加一个额外的参数并在函数内部处理它,如下所示:

def still_dreaming(self, some_arg):
        msg = some_arg + " Some people are still dreaming"
        return msg

然后我需要调用该函数并传递一个从我的模板中对其进行论证。像这样的事情:

<p tal:content="view/still_dreaming(item/publication_date)"></p>

不幸的是,我不知道将参数传递给方法的正确方法。任何指示将不胜感激。

编辑: item/publication_date 只是一些变量,可以是任何东西。它之前刚刚定义过。

I have been following this URL to help me create template views using BrowserView. So far, it works OK and I am able to create a template with a view class.

What I need to know is whether it is possible to pass arguments to methods inside the view class i.e.

from Products.Five import BrowserView

class Html(BrowserView):
    def still_dreaming(self):
        msg = "Some people are still dreaming"
        return msg

I need to add an extra argument to the still_dreaming function and process it inside the function like this:

def still_dreaming(self, some_arg):
        msg = some_arg + " Some people are still dreaming"
        return msg

Then I need to call the function and pass an argument to it from my template. Something like this:

<p tal:content="view/still_dreaming(item/publication_date)"></p>

Unfortunately, I do not know the correct way of passing arguments to the method. Any pointers will be greatly appreciated.

EDIT:
item/publication_date is just some variable and could be anything. It has just been defined previously.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎樣才叫好 2025-01-05 18:23:42

是的。

  <p tal:content="python:view.still_dreaming(item.publication_date)" />

您可以在 TAL 表达式中使用 TAL 遍历语法(默认)、Python 语法或字符串语法。

http://collective-docs.readthedocs.org/en/latest/functionity/expressions.html< /a>

Yes.

  <p tal:content="python:view.still_dreaming(item.publication_date)" />

You can use TAL traversing syntax (default), Python syntax or String syntax in TAL expressions.

http://collective-docs.readthedocs.org/en/latest/functionality/expressions.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文