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.