问题描述
class UserAccountManager(BaseUserManager):
def create_user(self,email,first_name,last_name,profile_pic,state,password=None):
"""
Creates and saves a User with the given email,firstname,lastname,profile picture,state of residence and password.
"""
if not email:
raise ValueError('Users must have an email address')
email = self.normalize_email(email)
user = self.model(
email=email,first_name=first_name,last_name=last_name,profile_pic=profile_pic,state=state
)
print("About to set the password")
user.set_password(password)
print("Set the user password,About to save")
user.save()
print("Saved the user")
return user
class User(AbstractUser):
email = models.EmailField(max_length=255,unique=True)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
profile_pic = models.ImageField(upload_to='images/',default="images/avatar.jpg")
state = models.CharField(max_length=100)
date_joined = models.DateTimeField(auto_now_add=True)
objects = UserAccountManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['first_name','last_name','profile_pic','state']
class Meta:
ordering = ('date_joined',)
def __str__(self):
return self.email
user.save() 没有运行。我尝试使用打印功能调试它,我发现“已保存用户”从未打印到终端,并且在向 API 发送发布请求时收到 404 错误。我使用 djoser API 进行身份验证。 Djoser API 返回
POST /auth/users/
HTTP 400 Bad Request
Allow: GET,POST,HEAD,OPTIONS
Content-Type: application/json
Vary: Accept
[
"Unable to create account."
]
任何帮助将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)