sshwsfc / xadmin

Drop-in replacement of Django admin comes with lots of goodies, fully extensible with plugin support, pretty UI based on Twitter Bootstrap.
http://www.xadmin.io
BSD 3-Clause "New" or "Revised" License
4.76k stars 1.41k forks source link

xadmin 在 django1.11.2 中出错 build_attrs() got an unexpected keyword argument 'name' #410

Closed bingoku closed 7 years ago

bingoku commented 7 years ago

本地测试环境

(devops) ➜  ~ python -V
Python 3.6.1
Package             Version
------------------- -------
Django              1.11.2
django-crispy-forms 1.6.1
django-formtools    2.0
django-reversion    2.0.8
future              0.16.0
httplib2            0.9.2
pip                 9.0.1
pytz                2017.2
setuptools          28.8.0
six                 1.10.0
xadmin              0.6.1
XlsxWriter          0.9.6
xlwt                1.2.0

出现的错误

TypeError at /xadmin/userwidget/add/

build_attrs() got an unexpected keyword argument 'name'

Request Method:     GET
Request URL:    http://127.0.0.1:8080/xadmin/userwidget/add/?user=1&page_id=home&_redirect=/
Django Version:     1.11.2
Exception Type:     TypeError
Exception Value:    

build_attrs() got an unexpected keyword argument 'name'

Exception Location:     /Users/nibuw/OneDrive/xadmin/demo_app/../xadmin/views/dashboard.py in render, line 39
Python Executable:  /Users/nibuw/.pyenv/versions/devops/bin/python
Python Version:     3.6.1
Python Path:    

['/Users/nibuw/OneDrive/xadmin/demo_app/..',
 '/Users/nibuw/OneDrive/xadmin/demo_app',
 '/Users/nibuw/.pyenv/versions/3.6.1/lib/python36.zip',
 '/Users/nibuw/.pyenv/versions/3.6.1/lib/python3.6',
 '/Users/nibuw/.pyenv/versions/3.6.1/lib/python3.6/lib-dynload',
 '/Users/nibuw/.pyenv/versions/devops/lib/python3.6/site-packages']

Server time:    星期五, 16 六月 2017 10:40:59 -0500

Error during template rendering

In template /Users/nibuw/.pyenv/versions/devops/lib/python3.6/site-packages/crispy_forms/templates/bootstrap3/field.html, error at line 28

build_attrs() got an unexpected keyword argument 'name'

18  
19          {% if field|is_checkboxselectmultiple %}
20              {% include 'bootstrap3/layout/checkboxselectmultiple.html' %}
21          {% endif %}
22  
23          {% if field|is_radioselect %}
24              {% include 'bootstrap3/layout/radioselect.html' %}
25          {% endif %}
26  
27          {% if not field|is_checkboxselectmultiple and not field|is_radioselect %}
28              {% if field|is_checkbox and form_show_labels %}
29                  <label for="{{ field.id_for_label }}" class="{% if field.field.required %} requiredField{% endif %}">
30                      {% crispy_field field %}
31                      {{ field.label|safe }}
32                  </label>
33                  {% include 'bootstrap3/layout/help_text_and_errors.html' %}
34              {% else %}
35                  <div class="controls {{ field_class }}">
36                      {% crispy_field field %}
37                      {% include 'bootstrap3/layout/help_text_and_errors.html' %}
38                  </div>
AlphaNotebook commented 7 years ago

我也遇到这个问题,我是这样解决了

  1. 打开E:\virtualenv\xxx_venv\Lib\site-packages\django\forms\widgets.py
  2. 在build_attrs()函数的定义处添加一个**kwargs
    def build_attrs(self, base_attrs, extra_attrs=None# , **kwargs):
        "Helper function for building an attribute dictionary."
        attrs = base_attrs.copy()
        if extra_attrs is not None:
            attrs.update(extra_attrs)
        return attrs
funtuanzi commented 7 years ago

Django 1.9

    def build_attrs(self, extra_attrs=None, **kwargs):
          "Helper function for building an attribute dictionary."
           attrs = dict(self.attrs, **kwargs)
          if extra_attrs:
             attrs.update(extra_attrs)
             return attrs

Django 1.11

     def build_attrs(self, base_attrs, extra_attrs=None):
           "Helper function for building an attribute dictionary."
           attrs = base_attrs.copy()
          if extra_attrs is not None:
             attrs.update(extra_attrs)
             return attrs

Modify xadmin/views/dashboard.py,

def render(self, name, value, attrs=None):
    print "!!!!!!!!xadmin\ view\ dashboard.py name is", name, ", attrs is", attrs
    if value is None:
        value = ''
    #final_attrs = self.build_attrs(attrs, name=name)
    attrs.update({u'name':name})
    final_attrs = self.build_attrs(attrs)