用户注册后端接口
models.py
from django.db import models # 用户表 class User(models.Model): name = models.CharField(max_length=32) password = models.CharField(max_length=255)
urls.py
from django.urls import path from . import views urlpatterns = [ path('login/',views.UserLoginView.as_view()), ]
views.py
from rest_framework.views import APIView from rest_framework.response import Response # 用户登录 class UserLoginView(APIView): # post方式提交 def post(self,request): # 获取前端传来的数据 data = request.data # 验证用户名和密码是否正确 obj = models.User.objects.filter(**data).first() # 判断 if obj: # 成功返回 return Response({ "status":200 }) # 失败返回 return return Response({ "status":201 })