سؤال

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