1. 程式人生 > >Django2.0 應用 Xadmin 報錯解決(補充)

Django2.0 應用 Xadmin 報錯解決(補充)

今天繼續研究Django 發現又有了新情況!解決方法奉上!

1、TypeError at /xadmin/

login() got an unexpected keyword argument 'current_app'錯誤
Exception Location: /home/wuchao/PycharmProjects/mxonline3/extra_apps/xadmin/views/website.py in get, line 66



解決方案:根據提示進入website,註釋61行
         

 #'current_app': self.admin_site.name,

2、AttributeError at /xadmin/

'Media' object has no attribute 'add_css'
Request Method: GET
Request URL: http://localhost:8000/xadmin/
Django Version: 2.0.1
Exception Type: AttributeError
Exception Value:
'Media' object has no attribute 'add_css'
Exception Location: /home/wuchao/PycharmProjects/mxonline3/extra_apps/xadmin/util.py in vendor, line 94

解決方案:
將util.py 中的86行 def vendor(*tags):方法體改為:

css = {'screen': []}
js = []
for tag in tags:
    file_type = tag.split('.')[-1]
    files = xstatic(tag)
    if file_type == 'js':
        js.extend(files)
    elif file_type == 'css':
        css['screen'] += files
return Media(css=css, js=js)

3、AttributeError at /xadmin/xadmin/log/

'DateTimeField' object has no attribute 'rel'
Request Method: GET
Request URL: http://localhost:8000/xadmin/xadmin/log/
Django Version: 2.0.1
Exception Type: AttributeError
Exception Value:
'DateTimeField' object has no attribute 'rel'
Exception Location: /home/wuchao/PycharmProjects/mxonline3/extra_apps/xadmin/views/list.py in get_list_queryset, line 228

修改 views/list.py 中228行

if isinstance(field.rel, models.ManyToOneRel):
    related_fields.append(field_name)

 修改為

if isinstance(field.remote_field, models.ManyToOneRel):
    related_fields.append(field_name)

後面繼續報這個“rel”的錯誤,解決方法參考3,根據 Exception Location 提示 找到Xadmin報錯行,將 field.rel 修改為 field.remote_field