天天看點

Django xadmin log頁面報錯

報錯資訊如下:

TypeError at /xadmin/xadmin/log/
__str__ returned non-string (type NoneType)
Request Method: GET
Request URL:    http://127.0.0.1:8000/xadmin/xadmin/log/
Django Version: 1.11.7
Exception Type: TypeError
Exception Value:    
__str__ returned non-string (type NoneType)
Exception Location: E:\python web project\SXDianShang\extra_apps\xadmin\plugins\details.py in result_item, line 52
Python Executable:  C:\Users\Administrator\SXDianShang\Scripts\python.exe
Python Version: 3.6.2
Python Path:    
['E:\\python web project\\SXDianShang\\extra_apps',
 'E:\\python web project\\SXDianShang\\apps',
 'E:\\python web project\\SXDianShang',
 'E:\\python web project\\SXDianShang',
 'E:\\python web project\\SXDianShang',
 'E:\\python web project\\SXDianShang\\apps',
 'E:\\python web project\\SXDianShang\\extra_apps',
 'C:\\Users\\Administrator\\SXDianShang\\Scripts\\python36.zip',
 'D:\\Program Files (x86)\\python\\DLLs',
 'D:\\Program Files (x86)\\python\\lib',
 'D:\\Program Files (x86)\\python',
 'C:\\Users\\Administrator\\SXDianShang',
 'C:\\Users\\Administrator\\SXDianShang\\lib\\site-packages',
 'C:\\Users\\Administrator\\SXDianShang\\lib\\site-packages\\setuptools-28.8.0-py3.6.egg',
 'C:\\Users\\Administrator\\SXDianShang\\lib\\site-packages\\pip-9.0.1-py3.6.egg',
 'C:\\Users\\Administrator\\SXDianShang\\lib\\site-packages\\odf',
 'C:\\Users\\Administrator\\SXDianShang\\lib\\site-packages\\odf',
 'C:\\Users\\Administrator\\SXDianShang\\lib\\site-packages\\odf',
 'C:\\Users\\Administrator\\SXDianShang\\lib\\site-packages\\odf',
 'C:\\Users\\Administrator\\SXDianShang\\lib\\site-packages\\odf',
 'C:\\Users\\Administrator\\SXDianShang\\lib\\site-packages\\odf',
 'C:\\Users\\Administrator\\SXDianShang\\lib\\site-packages\\odf']
           

網上查閱後,猜是因為str的問題

是以到model中将原來的

def __str__(self):
        #重載
        return self.name
           

改成

def __str__(self):
        #重載
        return str(self.name)
           

就可以正常使用xadmin log頁面了

這個問題的主要原因是該對象的主鍵不是一個字元串類型的主鍵,是以這裡把models中的def str(self):的傳回結果處理一下就好了。