TypeError: “ModelBase is not iterable”
再寫django專案時,出現錯誤TypeError: “ModelBase is not iterable”
原因是將models.py
中定義的類作為引數傳入了序列化器中,
比如models.py
中這個類叫做Login
serializers.py
中定義的類叫做Loginserializers
在傳入序列化器時:
Loginserializers(Login,many=True)
這樣直接將models.py中定義的類作為引數傳入了序列化器中,會導致錯誤TypeError: “ModelBase is not iterable”
正確寫法為:
Loginserializers(Login.objects.all(),many=True)
如果所寫的views.py
中的類繼承了APIView類,
將queryset = Login.objects.all()
,就i行了。
相關文章
- TypeError: Tensor objects are only iterable when eager execution is enabled. To iterate over this tErrorObject
- Iterable object of JavaScriptObjectJavaScript
- Javascript教程(七)iterableJavaScript
- python generator iterator和iterable objectPythonObject
- TypeError: SizeOnlySource is not a constructorErrorStruct
- TypeError: stringWidth is not a functionErrorFunction
- Iterator與Iterable(迭代器與可迭代)
- Uncaught TypeError: i is not a functionErrorFunction
- TypeError: object() takes no parametersErrorObject
- Uncaught TypeError: $(...).attr(...) is undefinedErrorUndefined
- 聊一聊Iterable與Iterator的那些事!
- TypeError: loaderContext.getOptions is not a functionErrorContextFunction
- Java中的Enumeration、Iterable和Iterator介面詳解Java
- TypeError: can‘t concat str to bytesError
- TypeError: Failed to fetch dynamically imported moduleErrorAIImport
- TypeError: Object of type ‘datetime‘ is not JSON serializableErrorObjectJSON
- js報錯:TypeError: Date is not a constructorJSErrorStruct
- pytorch 踩坑,TypeError: expected seqence object with len>_0 or a single integer_typeerror: expected sequence object with len __ 0PyTorchErrorObject
- react 和redux整合報TypeError: Object(...) is not a functionReactReduxErrorObjectFunction
- echarts:Uncaught TypeError: Cannot read property '0' of undefinedEchartsErrorUndefined
- Ruby中的TypeError異常處理Error
- TypeError: The ‘compilation‘ argument must be an instance of Compilation 報錯Error
- ReferenceError和TypeError有什麼區別?Error
- 1.python報錯:TypeError: 'int' object is not subscriptablePythonErrorObject
- Django程式碼中的TypeError 'float' object is not callableDjangoErrorObject
- TypeError: only integer scalar arrays can be converted to a scalar indexErrorIndex
- 求助:TypeError: unsupported format string passed to NoneType.__format__ErrorORMNone
- 如約而至!ModelBase:經緯恆潤自研車輛動力學模擬軟體
- 解決 TypeError: Type aliases cannot be used with isinstance(). 辦法Error
- TypeError: Descriptors cannot not be created directly問題的解決Error
- echarts 安裝 不顯示。TypeError: echarts__WEBPACK_EchartsErrorWeb
- Python報錯:TypeError: a bytes-like object is required, not ‘str‘PythonErrorObjectUI
- TypeError: TF_SessionRun_wrapper: expected all values in input dict to be ndarrayErrorSessionAPP
- Node.js 中 TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]Node.jsErrorImport
- jquery-3.4.1.js:10091 Uncaught TypeError: url.indexOf is not a functionjQueryJSErrorIndexFunction
- el-tree 報錯 TypeError: Cannot read property ‘setCheckedKeys‘ of undefined“ErrorUndefined
- VUE前端打包報錯:TypeError: Class extends value undefined is not a constructor or nullVue前端ErrorUndefinedStructNull
- 問題解決:TypeError: unsupported format string passed to NoneType.__format__ErrorORMNone