我按照老师的课程,自己编辑了简单的viewset,但是我发现,如果继承(mixins.ListModelMixin,viewsets.GenericViewSet) 则可以正常获取数据,但是
(mixins.CreateModelMixin,mixins.ListModelMixin,viewsets.GenericViewSet) 就会报’str’ object is not callable
我查了很多资料,还是不明白为何,我DRF是最新版本,我看是支持当前django的版本的
viewset类:
class GoodsFavViewSet(mixins.CreateModelMixin,mixins.ListModelMixin,viewsets.GenericViewSet):
""“
商品收藏ViewSet
”""
queryset = GoodsFav.objects.all()
serializer_class = GoodsFavSerializer
以下是报错信息!
////////////////////////
TypeError at /goodsfavs/
'str' object is not callable
Request Method:
GET
Request URL:
http://127.0.0.1:8000/goodsfavs/
Django Version:
2.0.3
Exception Type:
TypeError
Exception Value:
'str' object is not callable
Exception Location:
C:\Users\Administrator\Envs\qingdraw3.0_project\lib\site-packages\rest_framework\relations.py in display_value, line 228
Python Executable:
C:\Users\Administrator\Envs\qingdraw3.0_project\Scripts\python.exe
Python Version:
3.7.3
Python Path:
['C:\\Users\\Administrator\\PycharmProjects\\MxShop\\extra_apps',
'C:\\Users\\Administrator\\PycharmProjects\\MxShop\\apps',
'C:\\Users\\Administrator\\PycharmProjects\\MxShop',
'C:\\Users\\Administrator\\PycharmProjects\\MxShop',
'C:\\Users\\Administrator\\PycharmProjects\\MxShop',
'C:\\Users\\Administrator\\PycharmProjects\\MxShop\\apps',
'C:\\Users\\Administrator\\PycharmProjects\\MxShop\\extra_apps',
'D:\\Program Files\\JetBrains\\PyCharm 2019.1.3\\helpers\\pycharm_display',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\Scripts\\python37.zip',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\DLLs',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\lib',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\Scripts',
'c:\\users\\administrator\\appdata\\local\\programs\\python\\python37\\Lib',
'c:\\users\\administrator\\appdata\\local\\programs\\python\\python37\\DLLs',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\lib\\site-packages',
'D:\\Program Files\\JetBrains\\PyCharm '
'2019.1.3\\helpers\\pycharm_matplotlib_backend',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\lib\\site-packages\\odf',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\lib\\site-packages\\odf',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\lib\\site-packages\\odf',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\lib\\site-packages\\odf',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\lib\\site-packages\\odf',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\lib\\site-packages\\odf',
'C:\\Users\\Administrator\\Envs\\qingdraw3.0_project\\lib\\site-packages\\odf']
Django REST framework课程视频,RESTFul API前后端分离开发
了解课程