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介面
- Iterable object of JavaScriptObjectJavaScript
- Javascript教程(七)iterableJavaScript
- python generator iterator和iterable objectPythonObject
- TypeError: object() takes no parametersErrorObject
- Uncaught TypeError: $(...).attr(...) is undefinedErrorUndefined
- TypeError: SizeOnlySource is not a constructorErrorStruct
- Uncaught TypeError: i is not a functionErrorFunction
- Iterator與Iterable(迭代器與可迭代)
- TypeError:a.replaceisnotafunction錯誤ErrorFunction
- 聊一聊Iterable與Iterator的那些事!
- Java中的Enumeration、Iterable和Iterator介面詳解Java
- Spark 優化GroupByKey產生RDD[(K, Iterable[V])]Spark優化
- js報錯:TypeError: Date is not a constructorJSErrorStruct
- Uncaught TypeError: Object # has no method 'load'ErrorObject
- TypeError: loaderContext.getOptions is not a functionErrorContextFunction
- TypeError: Failed to fetch dynamically imported moduleErrorAIImport
- 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
- TypeError: Object of type ‘datetime‘ is not JSON serializableErrorObjectJSON
- TypeError: can‘t concat str to bytesError
- Ruby中的TypeError異常處理Error
- echarts:Uncaught TypeError: Cannot read property '0' of undefinedEchartsErrorUndefined
- jqGrid 兩種列模型(TypeError: b is undefined)模型ErrorUndefined
- 學習java筆記 --- 一個實現Iterable介面的小范例Java筆記
- echarts 安裝 不顯示。TypeError: echarts__WEBPACK_EchartsErrorWeb
- TypeError: only integer scalar arrays can be converted to a scalar indexErrorIndex
- Django程式碼中的TypeError 'float' object is not callableDjangoErrorObject
- 1.python報錯:TypeError: 'int' object is not subscriptablePythonErrorObject
- Uncaught TypeError: Object [object Object] has no method 'xxx'ErrorObject
- TypeError: Descriptors cannot not be created directly問題的解決Error
- 解決 TypeError: Type aliases cannot be used with isinstance(). 辦法Error
- TypeError: The ‘compilation‘ argument must be an instance of Compilation 報錯Error
- 求助:TypeError: unsupported format string passed to NoneType.__format__ErrorORMNone
- js 函式報錯“Uncaught: TypeError xxx is not a function”JS函式ErrorFunction
- 如約而至!ModelBase:經緯恆潤自研車輛動力學模擬軟體
- Python報錯:TypeError: a bytes-like object is required, not ‘str‘PythonErrorObjectUI