我正在尝试获取一个 z3c form.Form 来填写其信息,而不是在 url 中创建一个 get 参数,我想使用 publishTraverse。
所以这是我的代码的一部分:
my_object_view.py:
class EditMyObject(form.Form):
fields = field.Fields(IMyObject)
ignoreContext = False
myObjectID = None
def publishTraverse(self, request, name):
print "Is this firing?"
if self.myObjectID is None:
self.myObjectID = name
return self
else:
raise NotFound()
def updateWidgets(self):
super(EditMyObject,self).updateWidgets()
#set id field's mode to hidden
def getContent(self):
db_utility = queryUtility(IMyObjectDBUtility, name="myObjectDBUtility")
return db_utility.session.query(MyObject).filter(MyObject.My_Object_ID==self.myObjectID).one()
#Button handlers for dealing with form also added
.....
from plone.z3cform.layout import wrap_form
EditMyObjectView = wrap_form(EditMyObject)
在浏览器文件夹中的 configure.zcml 文件中:
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:zcml="http://namespaces.zope.org/zcml"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="my.object">
<browser:page
name="myobject-editform"
for="*"
permission="zope2.View"
class=".my_object_view.EditMyObjectView"
/>
</configure>
当我在 url 中使用 get 参数时,我能够让它工作,但是当我尝试使用 publishTraverse 时,我得到了找不到页面的错误。奇怪的是,当
顺便说一下,当我尝试使用发布遍历时,这就是我的网址:
http://localhost:8190/MyPloneSite/@@myobject-editform/1
当我省略 1,但保留“/”时,它仍然会找到该页面。我做错了什么导致这种情况?