zoukankan      html  css  js  c++  java
  • 检查用户名是否使用接口

    1.django添加检查用户名和手机号数量接口

    1.1 在`user/urls.py`中添加

    urlpatterns = [
        path('count/', views.RegCountView.as_view()),  # 查询用户名手机号使用量的视图,  /user/count/
    ]

    1.2 在`user/views.py`中添加视图函数

    # 查询用户数量接口
    class RegCountView(APIView):
        # 注册时需要验证的用户名和手机号是否使用
    
        # 自定义权限类
        permission_classes = (AllowAny,)
    
        def post(self, request):
            # 接收参数:  验证的内容type: username/phone,  data: '用户名' 或者 '手机号',
            datatype = request.data.get('type')
            data = request.data.get('data')
            if not all([data, datatype]):
                return Response({'code': 999, 'msg': '参数不完整'})
            if datatype == 'username':
                count = User.objects.filter(username=data).count()
            if datatype == 'phone':
                count = User.objects.filter(phone=data).count()
    
            return Response({'code': 0, 'msg': '查询成功', 'data': {'type': datatype, 'count': count}})

    2.测试接口

    2.1测试接口URL

    http://192.168.56.100:8888/user/count/

    2.2演示结果

    <img src="assets/image-20200922112242379.png" style=" 600px; margin-left: 50px;"> </img>

  • 相关阅读:
    网络流 方阵移动
    NOI2019滚粗记
    PKUSC2019游记
    CQOI十二省联考游记
    数学结论题 书堆
    计算几何 大灾变
    51NOD 1773 A国的贸易
    BZOJ 3944
    51Nod 1238
    NOIP2018游记
  • 原文地址:https://www.cnblogs.com/spbyyy/p/13779070.html
Copyright © 2011-2022 走看看