2017-04-05 91 views
2

我從1.10.7更新到1.11.0,並且在查看錶單時出現以下錯誤。我無法理解我的表格有什麼問題。其他形式的工作方式相同。我懷疑它可能是與select2markdownx的互動,但沒有跡象表明它們與1.11不兼容。更新到1.11:TypeError build_attrs()至多需要2個參數(給出3個)

如何進一步調試?

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'}), 
     } 
+0

@Alasdair我這樣做,如果有幫助。 – Sardathrion

回答

1

他們在Django 1.11改變了build_attrs功能/

您可能還需要使用pip升級select2和markdownx。

pip install select2 markdownx --upgrade

0

在Django的1.11更新,他們改變了build_attrs類只使用2個參數,你的所有附加參數現在應該在一個字典進行傳遞。

所以,當你使用一個使用build_attrs功能的自定義窗口小部件,您需要更改build_attrs撥叫:

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

到:

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

因此,罪魁禍首是選擇二類。您可以通過使用新方法對超級類別進行超級分類和覆蓋渲染功能來自行解決問題,也可以檢查作者是否有更新。

相關問題