Plon 4:将参数传递给视图类(BrowserView)
我一直在关注此网址来帮助我创建使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。
您可以在 TAL 表达式中使用 TAL 遍历语法(默认)、Python 语法或字符串语法。
http://collective-docs.readthedocs.org/en/latest/functionity/expressions.html< /a>
Yes.
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