首页 > 移动平台 > 详细

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

时间:2020-06-20 13:17:30      阅读:81      评论:0      收藏:0      [点我收藏+]

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项目_手机号唯一性验证

原文:https://www.cnblogs.com/jalen-123/p/13168134.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!