import re
from django.contrib.auth import authenticate, login
from django.db.models import QuerySet
from django.http import HttpRequest, HttpResponse, HttpResponseForbidden, JsonResponse
from django.shortcuts import render, redirect
# Create your views here.from django.views import View
from users.models import User
classMobileCountView(View):defget(self, request:HttpRequest, mobile):'''
查询手机号码对应的用户的个数
'''
count = User.objects.filter(mobile= mobile).count()return JsonResponse({'code':0,"errmsg":"ok","count": count})
from django.urls import re_path, include
from users import views
urlpatterns =[re_path(r"^register/$",views.RegisterView.as_view()),re_path(r"^usernames/(?P<username>[a-zA-Z0-9]{5,20})/count/$",views.UserNameCountView.as_view()),re_path(r"^mobiles/(?P<mobile>1[3-9]\d{9})/count/$",views.MobileCountView.as_view()),]