繁体   English   中英

更新到1.11:TypeError build_attrs()最多需要2个参数(给定3个)

[英]Update to 1.11: TypeError build_attrs() takes at most 2 arguments (3 given)

我从1.10.7更新到1.11.0,我在查看表单时收到以下错误。 我根本无法理解我的形式有什么问题。 其他形式以相同的方式工作。 我怀疑它可能是与select2markdownx的交互,但没有迹象表明这些与1.11不兼容。

我该如何进一步调试?

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)

File "/home/usr/repos/intranet/isotek_intranet_site/order_book/views.py" in create
  161.     return render(request, 'order_book/create.html', context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/shortcuts.py" in render
  30.     content = loader.render_to_string(template_name, context, request, using=using)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  68.     return template.render(context, request)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/backends/django.py" in render
  66.             return self.template.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render
  207.                     return self._render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in _render
  199.         return self.nodelist.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  177.             return compiled_parent._render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in _render
  199.         return self.nodelist.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  72.                 result = block.nodelist.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render
  990.                 bit = node.render_annotated(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render_annotated
  957.             return self.render(context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render
  1046.         return render_value_in_context(output, context)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/template/base.py" in render_value_in_context
  1024.     value = force_text(value)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/utils/encoding.py" in force_text
  78.                 s = six.text_type(s)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/utils/html.py" in <lambda>
  376.         klass.__unicode__ = lambda self: mark_safe(klass_unicode(self))

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/boundfield.py" in __str__
  41.         return self.as_widget()

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/boundfield.py" in as_widget
  120.             **kwargs

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/widgets.py" in render
  220.         context = self.get_context(name, value, attrs)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/widgets.py" in get_context
  665.         context = super(Select, self).get_context(name, value, attrs)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/widgets.py" in get_context
  626.         context = super(ChoiceWidget, self).get_context(name, value, attrs)

File "/home/usr/.virtualenvs/intranet/lib/python2.7/site-packages/django/forms/widgets.py" in get_context
  211.             'attrs': self.build_attrs(self.attrs, attrs),

Exception Type: TypeError at /order_book/create/
Exception Value: build_attrs() takes at most 2 arguments (3 given)

模板:

<form action="/order_book/invoice/create/" method="post">
{% csrf_token %}
<input type='hidden' name='action' value='create'>

<table>
    <tr>
        <td>{{ form.active.label }}</td>
        <td>{{ form.active }}</td>
    </tr>
    <!-- other entries like the one above… -->
    <tr>
        <td>
            <button type="submit" value="Add"><img src="/static/images/tick.png" alt="Set">
                Create new project code</button>
        </td>
    </tr>
</table>

风景:

def create_code(request):  # pragma: no cover
    context = {}
    if request.method == 'POST':
        form = MyForm(request.POST)
        if form.is_valid():
            pass  # Clearly for testing…
    form = MyForm()
    context['form'] = form
    return render(request, 'order_book/create_code.html', context)

表格:

class MyForm(forms.ModelForm):

    class Meta:
        model = MyModel
        fields = '__all__'
        widgets = {
           'manager': Select2Widget(attrs={'style': 'min-width:400px'}),
        }

他们改变了Django 1.11中的build_attrs函数/

您可能还需要使用pip升级select2和markdownx。

pip install select2 markdownx --upgrade

在Django 1.11更新中,他们将build_attrs类更改为仅使用2个参数,其中所有额外参数现在应该在dict中传递。

因此,当您使用使用build_attrs函数的自定义窗口小部件时,您需要更改build_attrs调用:

build_attrs(attrs, foo='bizz', bar='baz')

至:

build_attrs(attrs, {'foo':'bizz', 'bar':'baz'})

因此,罪魁祸首是Select2类。 您可以通过使用新方法超级分类和覆盖渲染功能来自行修复它,或者您可以检查作者是否有更新。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM