FormEncode验证失败后,使用查询字符串参数重新呈现Pylons表单
我的问题可能与此相同,但建议的答案似乎没有帮助(或者我没有正确理解):Pylons FormEncode @validate decorator将参数传递给重新渲染动作
我有一个简单的表单,它采用必需的查询字符串(id)值,将其用作隐藏的表单字段值,并验证发布的数据。控制器看起来像这样:
class NewNodeForm(formencode.Schema):
parent_id = formencode.validators.Int(not_empty = True)
child_name = formencode.validators.String(not_empty = True)
def newnode(self, id):
c.parent_id = id
return render('newnode.html')
@validate(schema=NewNodeForm(), form='newnode')
def createnode(self):
parentId = self.form_result.get('parent_id')
childName = self.form_result.get('child_name')
nodeId = save_the_data(parentId, childName)
return redirect_to(controller = 'node', action = 'view', id = nodeId)
形式很基础:
<form method="post" action="/node/createnode">
<input type="text" name="child_name">
<input type="hidden" value="${c.parent_id}" name="parent_id">
<input name="submit" type="submit" value="Submit">
</form>
如果验证通过,一切正常,但如果失败,则无法调用newnode
,因为id
不会被传回。它抛出TypeError: newnode() takes exactly 2 arguments (1 given)
。简单地定义为newnode(self, id = None)
可以解决这个问题,但我不能这样做,因为逻辑需要id。
这看起来很简单,但我错过了什么?
没有找到相关结果
已邀请:
2 个回复
臀夯脖锑
队辅坟阮阶
装饰器会使用修改后的
对象调用
,但所有GET / POST参数都不能更改