티스토리 뷰

 

AssertionError at /accounts/6/follow/
Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from the view, but received a `<class 'NoneType'>`
Request Method:POSTRequest URL:http://127.0.0.1:8000/accounts/6/follow/Django Version:3.2.9Exception Type:AssertionError
# 팔로우
@api_view(['POST'])
@permission_classes([AllowAny])
def follow(request, user_pk):
	...
    data = {
        'message' : 'follow!'
    }
    return JsonResponse(data=data)

- 에러: Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned from the view, but received a `<class 'NoneType'>`

- 문제점 : Serializer를 리턴하는 함수가 아니다보니, 따로 리턴을 적지 않았다.

- 해결방안 : 임의의 데이터를 넣어 Json Response를 호출

 

- 해결 방법 참고

https://stackoverflow.com/questions/67092036/django-restapi-assertionerror-expected-a-response-httpresponse-or-https

 

Django RestAPI - AssertionError: Expected a `Response`, `HttpResponse` or `HttpStreamingResponse` to be returned

I am New to Django Rest Framework. And Am trying to Build RESTapis for my project. However I am getting following error - AssertionError: Expected a Response, HttpResponse or HttpStreamingResponse ...

stackoverflow.com

 

'Django Framework' 카테고리의 다른 글

[DRF] StringRelatedField  (0) 2021.11.24
[DRF] Nested Relationships Serializer  (0) 2021.11.23
Django Movie 프로젝트 관련 QuerySet API  (0) 2021.11.19
Django RESTful Framework  (0) 2021.11.15
HTTP & API  (0) 2021.11.15
댓글