1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
# 手机是否存在接口 import re classMobileViewSet(ViewSet): defcheck(self, request, *args, **kwargs): mobile = request.data.get('mobile', None) ifnot mobile: return APIResponse(1, 'mobile field required') ifnot re.match(r'^1[3-9][0-9]{9}$', mobile): return APIResponse(1, 'mobile field error') try: models.User.objects.get(mobile=mobile) return APIResponse(result=True) # 手机号存在 except: return APIResponse(result=False) # 手机号不存在
|