用户模型如下。
class User(AbstractUser):
username = None
email = models.EmailField('email address', unique=True)
first_name = models.CharField('First Name', max_length=255, blank=True,
null=False)
last_name = models.CharField('Last Name', max_length=255, blank=True,
null=False)
objects = UserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']
用户配置文件模型如下。
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name='profile', on_delete=models.CASCADE)
avatar = models.ImageField(upload_to=avatar_image, blank=True, null=True) Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这是有道理的。请注意,django 使用
PIL库来处理图像在你的虚拟环境中
pip 安装pillow在你的models.py图像作为静态文件处理。 此处描述了处理静态文件