小白变大师 2020-01-06 16:01 采纳率: 100%
浏览 400
已采纳

Django后台管理新建post保存出错

报错如下

TypeError at /admin/blog/post/add/
object of type 'int' has no len()
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/blog/post/add/
Django Version: 3.0.1
Exception Type: TypeError
Exception Value:

object of type 'int' has no len()
Exception Location: C:\Users\Administrator\Desktop\website\djangoenv\lib\site-packages\django\forms\models.py in has_changed, line 1354
Python Executable: C:\Users\Administrator\Desktop\website\djangoenv\Scripts\python.exe
Python Version: 3.6.5
Python Path:

['C:\Users\Administrator\Desktop\website\blog2020',
'C:\Users\Administrator\Desktop\website\djangoenv\Scripts\python36.zip',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\DLLs',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\lib',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32',
'C:\Users\Administrator\Desktop\website\djangoenv',
'C:\Users\Administrator\Desktop\website\djangoenv\lib\site-packages']
Server time: 星期一, 6 一月 2020 15:56:18 +0800

源代码

def has_changed(self, initial, data):
if self.disabled:
return False
if initial is None:
initial = []
if data is None:
data = []
if len(initial) != len(data):
return True
initial_set = {str(value) for value in self.prepare_value(initial)}
data_set = {str(value) for value in data}
return data_set != initial_set

  • 写回答

1条回答

  • 'ゞBibo。 2020-01-06 16:07
    关注

    object of type 'int' has no len() 1354行你给int类型使用了len的方法

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?