Skip to content

Commit

Permalink
account状态码使用rest_framework内置staus
Browse files Browse the repository at this point in the history
  • Loading branch information
boyxiaolong committed Aug 30, 2016
1 parent 5f28f92 commit 7463591
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from utils.shortcuts import (serializer_invalid_response, error_response,
success_response, error_page, paginate, rand_str)
from utils.captcha import Captcha
Expand Down Expand Up @@ -154,10 +155,10 @@ def get(self, request):
if username:
try:
User.objects.get(username=username)
return Response(status=400)
return Response(status=status.HTTP_400_BAD_REQUEST)
except User.DoesNotExist:
return Response(status=200)
return Response(status=200)
return Response(status=status.HTTP_200_OK)
return Response(status=status.HTTP_200_OK)


class EmailCheckAPIView(APIView):
Expand All @@ -170,11 +171,11 @@ def get(self, request):
reset = request.GET.get("reset", None)
# 如果reset为true说明该请求是重置密码页面发出的,要返回的状态码应正好相反
if reset:
existed = 200
does_not_existed = 400
existed = status.HTTP_200_OK
does_not_existed = status.HTTP_400_BAD_REQUEST
else:
existed = 400
does_not_existed = 200
existed = status.HTTP_400_BAD_REQUEST
does_not_existed = status.HTTP_200_OK

email = request.GET.get("email", None)
if email:
Expand Down

0 comments on commit 7463591

Please sign in to comment.