简体   繁体   English

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

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

I a updating from 1.10.7 to 1.11.0 and I am getting the following error when viewing a form. 我从1.10.7更新到1.11.0,我在查看表单时收到以下错误。 I cannot fathom what is wrong with my form at all. 我根本无法理解我的形式有什么问题。 Other forms work in the same way. 其他形式以相同的方式工作。 I suspect that it could be an interaction with either select2 or markdownx but there is no indication that those are incompatible with 1.11. 我怀疑它可能是与select2markdownx的交互,但没有迹象表明这些与1.11不兼容。

How can I debug this further? 我该如何进一步调试?

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)

The template: 模板:

<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>

The view: 风景:

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)

The form: 表格:

class MyForm(forms.ModelForm):

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

They changed the build_attrs function in Django 1.11/ 他们改变了Django 1.11中的build_attrs函数/

You may need to upgrade also select2 and markdownx with pip. 您可能还需要使用pip升级select2和markdownx。

pip install select2 markdownx --upgrade

In the Django 1.11 update, they change the build_attrs class to use only 2 arguments, where all your extra arguments should now be passed in a dict. 在Django 1.11更新中,他们将build_attrs类更改为仅使用2个参数,其中所有额外参数现在应该在dict中传递。

So when you use a custom widget that uses the build_attrs function, you need to change the build_attrs call from: 因此,当您使用使用build_attrs函数的自定义窗口小部件时,您需要更改build_attrs调用:

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

to: 至:

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

Thus the culprit is the Select2 class. 因此,罪魁祸首是Select2类。 You can fix it yourself by super-classing and overwriting the render function with the new method or you can check if the author has an update. 您可以通过使用新方法超级分类和覆盖渲染功能来自行修复它,或者您可以检查作者是否有更新。

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

相关问题 Python 数据集更新 - TypeError: update() 最多需要 2 个位置参数(给出 3 个) - Python dataset update - TypeError: update() takes at most 2 positional arguments (3 given) TypeError:__init __()最多接受2个参数(给定4个) - TypeError: __init__() takes at most 2 arguments (4 given) TypeError:function()最多接受6个参数(给定7个) - TypeError: function() takes at most 6 arguments (7 given) Python — TypeError: format() 最多接受 2 个参数(给出 3 个) - Python — TypeError: format() takes at most 2 arguments (3 given) Python TypeError:int() 最多接受 2 个参数(给出 3 个) - Python TypeError: int() takes at most 2 arguments (3 given) TypeError:file()最多需要3个参数(给定4个参数) - TypeError: file() takes at most 3 arguments (4 given) TypeError:execute()最多接受3个参数(给定11个) - TypeError: execute() takes at most 3 arguments (11 given) 类型错误:UMat() 最多接受 2 个参数(给出 3 个) - TypeError: UMat() takes at most 2 arguments (3 given) TypeError: function takes at most 2 arguments (4 given) - TypeError: function takes at most 2 arguments (4 given) 在django admin上注册4个参数-TypeError:register()最多接受3个参数(给定4个) - register 4 arguments on django admin - TypeError: register() takes at most 3 arguments (4 given)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM