个人报错TypeError: ‘type‘ object is not iterable
django报错 ‘type’ object is not iterable,个人报错原因解析
E:\django_project\my_blog\article\models.py changed, reloading.
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):File "E:\Python\Python37\lib\threading.py", line 926, in _bootstrap_innerself.run()File "E:\Python\Python37\lib\threading.py", line 870, in runself._target(*self._args, **self._kwargs)File "E:\django_project\my_blog\venv\lib\site-packages\django\utils\autoreload.py", line 54, in wrapperfn(*args, **kwargs)File "E:\django_project\my_blog\venv\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_runautoreload.raise_last_exception()File "E:\django_project\my_blog\venv\lib\site-packages\django\utils\autoreload.py", line 77, in raise_last_exceptionraise _exception[1]File "E:\django_project\my_blog\venv\lib\site-packages\django\core\management\__init__.py", line 337, in executeautoreload.check_errors(django.setup)()File "E:\django_project\my_blog\venv\lib\site-packages\django\utils\autoreload.py", line 54, in wrapperfn(*args, **kwargs)File "E:\django_project\my_blog\venv\lib\site-packages\django\__init__.py", line 24, in setupapps.populate(settings.INSTALLED_APPS)File "E:\django_project\my_blog\venv\lib\site-packages\django\apps\registry.py", line 122, in populateapp_config.ready()File "E:\django_project\my_blog\venv\lib\site-packages\django\contrib\admin\apps.py", line 24, in readyself.module.autodiscover()File "E:\django_project\my_blog\venv\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscoverautodiscover_modules('admin', register_to=site)File "E:\django_project\my_blog\venv\lib\site-packages\django\utils\module_loading.py", line 47, in autodiscover_modulesimport_module('%s.%s' % (app_config.name, module_to_search))File "E:\Python\Python37\lib\importlib\__init__.py", line 127, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)File "<frozen importlib._bootstrap>", line 1006, in _gcd_importFile "<frozen importlib._bootstrap>", line 983, in _find_and_loadFile "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 677, in _load_unlockedFile "<frozen importlib._bootstrap_external>", line 728, in exec_moduleFile "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removedFile "E:\django_project\my_blog\article\admin.py", line 7, in <module>admin.site.register(ArticlePost)File "E:\django_project\my_blog\venv\lib\site-packages\django\contrib\admin\sites.py", line 102, in registerfor model in model_or_iterable:
TypeError: 'type' object is not iterable
网上查找很多,但是都对不上,有的竟然要改源码。然后仔细过了一遍报错前写过的代码,找到错误原因:
定义models的类时,忘记添加继承了
from django.contrib.auth.models import User
from django.db import models# 博客文章数据模型
from django.utils import timezone# ↓↓↓↓↓↓↓↓↓↓报错原因↓↓↓↓↓↓↓
class ArticlePost():
# ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑# 文章作者, on_delete数据删除方式,此处是级联删除author = models.ForeignKey(User, on_delete=models.CASCADE)# 文章标题,max_length设置最大长度,并且不能为空title = models.CharField(max_length=100)# 文章正文内容body = models.TextField()# 文章创建时间,默认未创建数据的时间created = models.DateTimeField(default=timezone.now)# 文章更新时间,数据更新时,自动写入当前系统时间updated = models.DateTimeField(auto_now=True)class Meta:# ordering 指定模型返回数据的排列顺序# -created 表明数据倒叙排列ordering = ("-created",)# 函数 __str__(self)定义调用对象的 str() 方法时,返回值的内容def __str__(self):# 将文章的标题返回return self.title
修改后,class ArticlePost(models.Model):
from django.contrib.auth.models import User
from django.db import models# 博客文章数据模型
from django.utils import timezone# ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
class ArticlePost(models.Model):# 文章作者, on_delete数据删除方式,此处是级联删除author = models.ForeignKey(User, on_delete=models.CASCADE)# 文章标题,max_length设置最大长度,并且不能为空title = models.CharField(max_length=100)# 文章正文内容body = models.TextField()# 文章创建时间,默认未创建数据的时间created = models.DateTimeField(default=timezone.now)# 文章更新时间,数据更新时,自动写入当前系统时间updated = models.DateTimeField(auto_now=True)class Meta:# ordering 指定模型返回数据的排列顺序# -created 表明数据倒叙排列ordering = ("-created",)# 函数 __str__(self)定义调用对象的 str() 方法时,返回值的内容def __str__(self):# 将文章的标题返回return self.title
个人报错TypeError: ‘type‘ object is not iterable相关推荐
- Python报错TypeError: ‘User‘ object is not iterable
Python报错TypeError: 'User' object is not iterable 原因 User对象是不可迭代的,我这里是因为User并不是list,所以是不可迭代的,所以不使用迭代即 ...
- python 多进程multiprocessing进程池pool tensorflow-yolov3 报错TypeError: 'ApplyResult' object is not iterable
首先,代码结构它长这样: 可每次调用线程池进行识别时,就会报如下错误: D:\20191031_tensorflow_yolov3\python\python.exe D:/20191031_tens ...
- python 报错 AttributeError: type object ‘datetime.datetime‘ has no attribute ‘datetime‘
python报错:type object 'datetime.datetime' has no attribute 'datetime' 描述:在第一个python程序里还未报错,第二个程序完全复制过 ...
- Python报错TypeError: 'str' object is not callable
原文:http://blog.sina.com.cn/s/blog_71f3890901017rsh.html Python报错TypeError: 'str' object is not calla ...
- python nonetype object is not_python报错TypeError: ‘NoneType‘ object is not subscriptable的解决方法...
发现问题 写python的时候出现了这个错,然后网上的教程的解决方案几乎都是--"重新定义下这个变量",看的我一脸懵逼 后来发现原来是我把return None的方法赋给了变量,之 ...
- Python----方法返回None值报错 TypeError NoneType object is not callable
转载请声明,本文来自:https://blog.csdn.net/shijianduan1/article/details/106415395 相信很多小伙伴, 在遇到报错的时候,直接搜索报错内容, ...
- Python关于None的报错:'NoneType' object is not iterable和cannot unpack non-iterable NoneType object
文章目录 一.TypeError:'NoneType' object is not iterable(类型错误:'NoneType'对象不是可迭代的) 二.TypeError: cannot unpa ...
- python 报错 TypeError: ‘int‘ object is not subscriptable 解决方法
报错原因 整数上加了下标 不是数组 当作数组 使用 错误情况1: a = 4 c=a[2]# 或者 a = 4 index=2 c=a[index] 报错:line 2, in <module& ...
- python报错:TypeError: 'str' object is not callable
这个问题遇到好多次了,这次记录一下, 问题重现 代码仅保留最重要的: # summaries 是一个集合 # 求和并打印 result = 0 for str in summaries: result ...
最新文章
- Linux扫盲篇:CentOS、Ubuntu、Gento
- linux下用c 开发web,用C一步步开发web服务器(2)
- 关于 VB,VC,Delphi,SDK 的笑话
- 第28课 叮叮当当 《小学生C++趣味编程》
- python的枚举和for循环_python入门与进阶篇(三)之分支、循环、条件与枚举,python枚举...
- 更新macOS Big Sur系统后,Parallels Desktop打不开怎么办?教你解决方法!
- 【JAVA】初识Java
- vb.net word 自定义工具栏_20个Word文字处理快速掌握技巧
- 苹果开发者账号开启双重认证步骤
- 软件设计师第二章知识点_作为设计师,您可能会找到的最好的第二次展示
- 数据库设计(1)_概念结构设计
- ai智能语音机器人的新风向
- 专访Women in AI学者黄惠:绘图形之梦,寻突破之门
- 打开计算机管理窗口命令,Win7如何打开命令行窗口?打开命令行窗口的方法
- HDU 5454 Excited Database 线段树的维护
- 《失业的程序员》(十八):意外的项目之旅
- Java异常处理的普遍误解
- 京东顺丰江湖一战,在所难免!
- Mac 原神电脑版下载安装使用教程,MacBook 上也可以玩原神了
- 在线JSON转JAVA工具
热门文章
- 西邮计算机网络实验报告,西邮计算机网络实验报告内容模板-实验二-交换机基本配置...
- 《游戏系统设计七》重现王者荣耀抽奖系统
- vue-infinite-scroll无限滚动组件
- Python爬虫爬取豆瓣电影评论内容,评论时间和评论人
- MATLAB学习六:mean算数均值
- MFC的COleDateTime类使用
- 企业如何处理网上百度知道的负面信息?
- 全志r16android sdk,全志R16_sdk_Dmaengine使用手册
- Whale帷幄 - 企业数字化解决方案服务商 数字化方案提供商
- 2020第十一届蓝桥杯大赛软件类国赛 C/C++ 大学 B 组