devgraphy / airsm-django-restapi

AIRSM 프로젝트의 REST API 기반 Back-end
0 stars 0 forks source link

AssertionError: The `request` argument must be an instance of `django.http.HttpRequest`, not `rest_framework.request.Request`. #21

Open devgraphy opened 3 years ago

devgraphy commented 3 years ago

rest api로 받은 request 객체 인자를 view 함수인 membercreate에 그대로 전달하는 과정에서 이러한 이슈가 발생하였다.

AssertionError: The `request` argument must be an instance of 
`django.http.HttpRequest`, not `rest_framework.request.Request`.
[01/Jun/2021 00:48:37] "POST /membership/point/ HTTP/1.1" 500 133866
@api_view(['POST'])
def point(request):
    num = 50
    p = request.data.get('phone')
    print(p)
    try:
        obj = Member.objects.get(phone=p)
        obj.points+=num
        obj.save()
        print("o")
    except ObjectDoesNotExist:
        print("x")
        print(type(request))
        memberCreate(request)
        obj = Member.objects.get(phone=p)
        obj.points+=num
        obj.save()
    return Response(num, status=200)
devgraphy commented 3 years ago

일단은 point 함수 내에서 memberCreate를 호출하여 request를 전달하지 않고, point 함수 내에서 직접 serializer를 구현하고 save하여 구현해서 해결하였다.