Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

Because i have nginx route set, i am using cookies for authentication. The current code that i have in my views for signup are

@csrf_exempt
@api_view(['POST'])
def userSignin(request):
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
                login(request,form.get_user())
                serializer = userSerializer(user)
                return Response(serializer.data)
        return HttpResponse(form.errors.as_json())

My question is what is the right way that i can send output to the user so that it becomes easy for me to handle forms errors output and serializer output. What i had in mind is setting a flag status which is a boolean and conditionally parse output, but i am not able to code the same.

Also i would like if someone can guide me to some method so that i replace the HttpResponse with DRF Response for form errors.

share|improve this question

Rest framework itself provide status code of easy usage

if form is valid you can use

return Response(serializer.data, status=status. HTTP_202_ACCEPTED)

for more details www.django-rest-framework.org/api-guide/status-codes/

share|improve this answer
    
What about rejection? status code for that ? couldn't find that in api guide – georoot 2 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.