python - Plone 4 : Passing arguments to view class (BrowserView)

标签 python plone

我一直在关注this URL帮助我使用 BrowserView 创建模板 View 。到目前为止,它工作正常,我能够创建一个带有 View 类的模板。

我需要知道的是是否可以将参数传递给 View 类中的方法,即

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 只是一些变量,可以是任何东西。它之前刚刚定义过。

最佳答案

是的。

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

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

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

关于python - Plone 4 : Passing arguments to view class (BrowserView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9079019/

相关文章:

xpath - Collective.xdv 中的 local-name() 支持

python - 如何根据选择变量中的值将 PloneFormGen 重定向到页面?

image - 具有一种状态工作流程的 Plone 图像可见性

python - pandas 数据框 reshape /透视

python - 发电机 : How do I do a putItem but just if key doesn't exists in Python?

python - 如何按字典顺序对文件路径进行排序? Python

python - 在 Pandas 中读取、选择和重新排列列

python - 如何创建 for 循环来比较线性回归模型的训练和测试分数

python - 导入错误 : No module named testrunner

python - 我可以使用 plone 工作流来管理与 autocad 相关的图形吗?