开发者

Python Plone views call others

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 Pytho开发者_JS百科n 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...)


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]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜