django - Cutom 用户模型 save() 方法中的 Django 错误
问题描述
我有一个自定义用户模型,它可以正常工作,后来我为用户图像添加了字段,然后我可以注册但无法登录。
我认为 save() 方法有错误。
我不接受注册页面中的用户图像,但有模板供登录用户稍后添加
from django.db import models
from django.contrib.auth.models import AbstractUser
from PIL import Image
class User(AbstractUser):
email = models.EmailField(verbose_name='email' ,max_length=223,unique=True)
photo = models.ImageField(upload_to='prof_pic', blank=True,null=True)
phone=models.CharField(null=True,max_length=11)
REQUIRED_FIELDS = [ 'email','phone']
def save(self,*args, **kwargs):
super().save()
if self.photo:
pic = Image.open(self.photo.path)
if pic.height > 300 or pic.width > 300:
output_size = (300, 300)
pic.thumbnail(output_size)
pic.save(self.photo.path)
super(User, self).save(*args, **kwargs)
登录时出错
Please enter a correct username and password. Note that both fields may be case-sensitive.
解决方案
https://stackoverflow.com/a/8845337/10515390 检查此链接上的答案。
我添加了身份验证后端。
推荐阅读
- r - 具有权重变量的数据集:转换和统计分析
- ibm-doors - DXL:如何使用其路径获取模块的 ModName_
- gps - GPS未知问题
- reactjs - React SyncFusion资源和分组crud未绑定调度程序中的数据
- visual-studio-code - Rstudio 喜欢 VSCode/Julia 中的自动缩进
- amazon-s3 - 将文本文件上传到 S3 - 如何修改现有代码以上传图像
- java - Android:警报未通过 AlarmManager 触发
- python - 为什么我不能从 py-substrate-interface 发送外部信息?
- javascript - Sequelize 搜索 API 无法按预期工作 expressJS
- android - Android:使用带有多证书的 ApkSigner 为 APK 签名