Python Plone 视图调用其他视图
我有一个 Python 函数在 Plone 中注册为视图。我需要能够从这个注册函数中调用另一个函数。我不确定是否最好将这个其他函数也注册为视图并尝试调用它(不知道如何调用其他视图),或者是否有更好的方法来处理这个问题。
基本上,我正在 Python 中创建一个需要从其他 Python 函数(注册为视图)调用的函数。
- 编辑 - 我尝试像任何其他函数一样调用它:
(pytest.py)def 测试(自我):
return "TEST"
并在我的 Python 脚本中注册为视图:
import pytest
def PageFunction(self):
return pytest.Test()
然而,这似乎总是崩溃。如果我离开 pytest.Test() 并返回一个简单的字符串,它似乎工作正常(所以我不认为 import pytest
行引起任何问题...)
I have a Python function registered as a View in Plone. I need to be able to call another function from within this registered function. I'm not sure if it would be best to register this other function as a view as well and try to call that (don't know how to call other views), or if there is a better way to handle this.
Basically I'm creating a function in Python that needs to be callable from other Python functions (that are registered as Views).
- Edit -
I have tried calling it like any other function:
(pytest.py)def Test(self):
return "TEST"
And in my Python script registered as a view:
import pytest
def PageFunction(self):
return pytest.Test()
However, this always seems to crash. If I leave the pytest.Test()
out and return a simple string, it seems to work fine (so I don't think the import pytest
line is causing any problems...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需导入它并像任何其他函数一样调用它即可。您不想让它成为一个视图 - 这需要您进行 MultiAdapter 查找,这确实很痛苦,而且完全没有必要。
[编辑 - 严格使用视图是 MultiAdapter 查找,但您可以通过遍历来快捷方式,但这仍然不值得]
Just import it and call it as any other function. You don't want to make it a view - that requires you to do a MultiAdapter lookup which is a real pain, and completely unnecessary.
[Edit - strictly using a view is a MultiAdapter lookup, but you can shortcut it via traversal, but that still isn't worth the effort]