python项目_手机号唯一性验证

1.手机号码唯一性验证

"""
接口访问地址: /user/mobile/(?P<mobile>1[3-9]\d{9})/
"""
from rest_framework import status
class MobileAPIView(APIView):
    def get(self,request,mobile):
        """验证码手机号唯一性"""
        #1. 根据手机号到数据库里面查找用户,返回结果
        try:
            User.objects.get(mobile=mobile)
            return Response({"status": False}, status=status.HTTP_400_BAD_REQUEST)
        except User.DoesNotExist:
            return Response({"status": True}, status=status.HTTP_200_OK)

2.添加路由

from django.urls import path,re_path
from rest_framework_jwt.views import obtain_jwt_token
from . import views
urlpatterns = [
    path("login/", obtain_jwt_token),
    path("captcha/", views.GeetestCaptchaAPIView.as_view()),
    path("", views.UserAPIView.as_view()),
    re_path("mobile/(?P<mobile>1[3-9]\d{9})/", views.MobileAPIView.as_view()),
]

 

python项目_手机号唯一性验证

上一篇:前端获取后台数据的方法:ajax、axios、fetch


下一篇:jmeter录制app脚本