Question

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

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top