标签:后端 djang 登陆 手机 class EAP migration char serial
需要在django自带的用户模型类上增加邮箱激活状态email_active
class User(AbstractUser): """ 用户信息 """ mobile = models.CharField(max_length=11, unique=True, verbose_name="手机号") email_active = models.BooleanField(default=False, verbose_name=‘邮箱验证状态‘)
进行数据库迁移
python manage.py makemigrations
python manage.py migrate
在users/serializers.py中添加序列化器,用于将模型对象序列化后返回给前端
class UserDetailSerializer(serializers.ModelSerializer): """ 用户详细信息序列化器 """ class Meta: model = User fields = (‘id‘, ‘username‘, ‘mobile‘, ‘email‘, ‘email_active‘)
from rest_framework.permissions import IsAuthenticated class UserDetailView(RetrieveAPIView): """ 用户详情 """ serializer_class = serializers.UserDetailSerializer permission_classes = [IsAuthenticated] def get_object(self): return self.request.user
IsAuthenticated 权限 通过认证用户可访问,登陆过的
标签:后端 djang 登陆 手机 class EAP migration char serial
原文地址:https://www.cnblogs.com/whigym/p/10009249.html