报错信息如下:
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):的返回结果处理一下就好了。