2016-10-23 2 views
0

JsonResponse에 서버 응답 코드를 추가 할 수 있습니까? 어떤 상황에서는 404로 응답하기 위해 서버가 필요합니다.Django - JsonResponse의 서버 코드 응답

내가보기

def CreateOrAuth(request): 
try: 
    username = request.POST.get("username") 

    queryset = User.objects.get(username=username) 

except Exception as e: 
    return JsonResponse({'status': 'user with {} not exist'.format(username)}) 

다음했다 그리고 나는 여기에 404 서버 코드 예, 당신이 할 수있는

+1

이 답변을 확인하십시오 : http://stackoverflow.com/a/35059936/3065081를 [장고 JSON 응답 에러 상태 (HTTP의 –

+0

가능한 중복 : // 유래. co.kr/questions/35059916/django-json-response-error-status) – GwynBleidD

답변

1

을 추가 할 수 있습니다. 그냥 JsonResponse에 추가 매개 변수 status을 전달합니다

return JsonResponse({'status': 'user with {} not exist'.format(username)}, status=404)