File "E:\django_project\LibraryMS\users\views.py", line 16, in post action = request.data.get("action") AttributeError: 'WSGIRequest' object has no attribute 'data'

运行Django项目时:报此错误

附上源码:

class UserView(View):

    def post(self, request, *args, **kwargs):

        action = request.data.get("action")

        if action == "register":
            return self.register(request)
        elif action == "login":
            return self.login(request)
        else:
            return self.error(request)

用的是rest_framework框架制作用户的登录和注册。

经过分析得出:原来是使用CBV的时候继承错包了

解决方案::

将:
from django.views import View
class UserView(View):
改为:
from rest_framework.views import APIView
class UserView(APIView):
posted @ 2020-10-17 23:32  Morpheus1024  阅读(180)  评论(0编辑  收藏  举报