奇怪的变形/漏勺行为"字符串索引必须是整数"

时间:2014-05-25 21:36:49

标签: pyramid deform colander

所以我有以下工作代码,我过去几个月一直在使用

class UserSchema(colander.MappingSchema):
    dob = colander.SchemaNode(
            colander.Date(),
            title='Date of birth:')

 if 'submit' in request.POST:

    controls = request.POST.items()
    try:
        appstruct = myform.validate(controls)
    except ValidationFailure, e:
        return {'form':e.render(), 'values': False}

现在这是一个基本的日期选择器,如下所示:

http://deform2demo.repoze.org/dateinput/

但突然间,当使用这个小部件时,我收到了错误:

Traceback (most recent call last):
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid_debugtoolbar-1.0.9-py2.7.egg/pyramid_debugtoolbar/panels/performance.py", line 55, in resource_timer_handler
    result = handler(request)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid/tweens.py", line 21, in excview_tween
    response = handler(request)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid_tm-0.7-py2.7.egg/pyramid_tm/__init__.py", line 82, in tm_tween
    reraise(*exc_info)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid_tm-0.7-py2.7.egg/pyramid_tm/__init__.py", line 63, in tm_tween
    response = handler(request)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid/router.py", line 161, in handle_request
    response = view_callable(context, request)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid/config/views.py", line 347, in rendered_view
    result = view(context, request)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/pyramid/config/views.py", line 493, in _requestonly_view
    response = view(request)
  File "/home/luke/pyramids/getwork2day.co.uk/getwork2day/views/signup.py", line 244, in user_signup
    appstruct = myform.validate(controls)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/field.py", line 636, in validate
    return self.validate_pstruct(pstruct)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/field.py", line 661, in validate_pstruct
    cstruct = self.deserialize(pstruct)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/field.py", line 512, in deserialize
    return self.widget.deserialize(self, pstruct)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/widget.py", line 1274, in deserialize
    result[name] = subfield.deserialize(subval)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/field.py", line 512, in deserialize
    return self.widget.deserialize(self, pstruct)
  File "/home/luke/virts/pyramid-1.4.5/lib/python2.7/site-packages/deform-2.0a2-py2.7.egg/deform/widget.py", line 551, in deserialize
    date = pstruct['date'].strip()
TypeError: string indices must be integers

1 个答案:

答案 0 :(得分:0)

至少将当前表单控件转储到日志记录并在此处发布。试着变得更加冗长清楚你的代码示例,不要混淆漏勺模式代码和金字塔视图代码。

 if 'submit' in request.POST:

    controls = request.POST.items()
    try:
        appstruct = myform.validate(controls)
    except ValidationFailure, e:
        log.debug('form validation fails for %r' % controls)
        return {'form':e.render(), 'values': False}