문제

How can I get object from ZODB database in Zope3 project by url 'http://ecample.com/folder1/object1'?

obj1 = someMethod('http://ecample.com/folder1/object1')

Is there any tools of methods for this? Like absoluteUrl() but opposite? Or I must parse url and manually get object from db root?...Thanks

도움이 되었습니까?

해결책

You can turn a path into an object by using the traversing API:

from zope.traversing.api import traverse

obj = traverse(context, path)

You'll need a context to traverse from; use the site root for URL paths for example. If all you have is a URL, you'd need to parse out the path from it:

from urlparse import urlparse

path = urlparse(url).path
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top