【问题标题】:Crispy forms .wrap or .update_attributes buggy after previous creation of layout object之前创建布局对象后的脆皮表单 .wrap 或 .update_attributes 错误
【发布时间】:2015-09-03 11:19:44
【问题描述】:

我想为 UpdateView 布局一个特定的用户表单,然后根据提供的参数检查字段是否需要只读。但是我得到一个带有异常值“u'wrapper_class'”的“KeyError”异常。

users.views.py 中的示例

form_helper.layout = Layout(
        Fieldset(
            _('Personal information'),
            'username',
            'first_name',
            'last_name',
            'email',
            Field('password', type='hidden')
        ),
        HTML('<br/>'),
        Fieldset(
            _('Permissions'),
            'groups',
            Field('user_permissions', size=20)
        ),
        Field('date_joined', type='hidden'),
        'is_active'
    )

form_helper[:].wrap(Field, readonly=has_no_change_permission)

其中 has_no_change_permission 的计算结果为 True 或 False。 最后一行不起作用,我收到上述错误。

为什么?这个错误并没有告诉我太多。执行位置是: [...]/lib/python2.7/site-packages/django/template/context.py 在 delitem,第 75 行

顺便说一句:

form.helper[:].update_attributes(readonly=True)

似乎根本不起作用,我没有效果(也没有错误消息)。我错过了什么?

【问题讨论】:

    标签: permissions django-crispy-forms


    【解决方案1】:

    这是 Crispy Forms 中的一个错误。它已在 v1.5.2 中修复

    【讨论】:

      猜你喜欢
      • 2019-04-24
      • 1970-01-01
      • 2015-01-07
      • 1970-01-01
      • 2020-08-21
      • 2018-06-30
      • 2017-03-19
      • 2014-02-28
      • 2019-12-21
      相关资源
      最近更新 更多