第一步先建表:
第二步写接口:
# TODO 注册接口 def register(request): email = request.POST.get('email') phone = request.POST.get("phone") nick = request.POST.get("nick") password1 = request.POST.get("password1") password2 = request.POST.get("password2") if all([email, phone, nick, password1, password2]): # if email and phone and nick and password1 and password2: if password1 != password2: return JsonResponse({"code": -1, "msg": "两次输入的密码不一致"}) email1 = models.NewUser.objects.filter(email=email) if email1.exists(): return JsonResponse({"code": -1, "msg": "邮箱已存在"}) phone1 = models.NewUser.objects.filter(phone=phone) if phone1.exists(): return JsonResponse({"code": -1, "msg": "手机号已存在"}) if len(phone) != 11: return JsonResponse({"code": -1, "msg": "手机号不合法"}) if len(phone) == 11: if re.match(r'13[0,1,2]\d{8}', phone) or \ re.match(r"15[5,6]\d{8}", phone) or \ re.match(r"18[5,6]", phone) or \ re.match(r"145\d{8}", phone) or \ re.match(r"176\d{8}", phone): models.NewUser(email=email, phone=phone, nick=nick, password=md5(password1)).save() return JsonResponse({"code": 0, "msg": "注册成功"}) if re.match(r"13[4,5,6,7,8,9]\d{8}", phone) or \ re.match(r"147\d{8}|178\d{8}", phone) or \ re.match(r"15[0,1,2,7,8,9]\d{8}", phone) or \ re.match(r"18[2,3,4,7,8]\d{8}", phone): models.NewUser(email=email, phone=phone, nick=nick, password=md5(password1)).save() return JsonResponse({"code": 0, "msg": "注册成功"}) if re.match(r'133\d{8}', phone) or \ re.match(r"153\d{8}", phone) or \ re.match(r"189\d{8}", phone): models.NewUser(email=email, phone=phone, nick=nick, password=md5(password1)).save() return JsonResponse({"code": 0, "msg": "注册成功"}) else: return JsonResponse({"code": -1, "msg": "not null"})