![](/img/trans.png)
[英]Python: Why changing `from constants import API_TOKEN to `import constants` cause errors?
[英]command: "from plone import api " producing errors
我正在使用 VM Virtual Box 運行 Plone 實例。 啟動實例后,當我在機器中輸入導入命令:“from plone import api”時,出現錯誤:from can't read /var/mail/plone.
即使我在導入命令之前輸入:“#!/usr/bin/env python”,我也會得到同樣的錯誤
當我輸入 python,然后輸入命令:“from plone import api”時,我收到一個錯誤:沒有名為 plone 的模塊。
我該怎么辦?
如果您通過bin/instance debug
啟動 zope 站點,則不清楚應該使用哪個plone
站點,因為可能有多個站點。
所以你首先需要定義 plone 站點plone.api
應該使用什么。 這是通過將站點管理器指向您的 plone 站點來完成的。
./bin/instance debug
Starting debugger (the name "app" is bound to the top-level Zope object)
...
...
>>>
>>> api.portal.get() # Will not work
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/path/to/egg/plone.api.egg/plone/api/portal.py", line 82, in get
'Unable to get the portal object. More info on '
CannotGetPortalError: Unable to get the portal object. More info on http://docs.plone.org/develop/plone.api/docs/api/exceptions.html#plone.api.exc.CannotGetPortalError
>>> plone = app.get('my-plone-site')
>>> plone
<PloneSite at /my-plone-site>
>>> from zope.component.hooks import setSite
>>> setSite(plone)
>>> from plone import api
>>> api.portal.get()
<PloneSite at /my-plone-site>
就是這樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.