gpt4 book ai didi

python - 经理不在; 'auth.User' 已替换为 'users.User'

转载 作者:太空宇宙 更新时间:2023-11-03 20:18:22 28 4
gpt4 key购买 nike

1 当我希望出现注册错误时,我的代码出现问题:管理器不可用; 'auth.User' 已替换为 'users.User' ,我尝试解决其他问题,与 Manager 不可用相同; 'auth.User' 已被替换为 'members.customer' 但他们都要求替换 User = User = get_user_model() 但我没有在我的代码中使用任何 User 或者我不知道我在哪里使用过它。我django、python、js 等中的新功能,所以如果我的问题很愚蠢请原谅我。

错误:

AttributeError at /accounts/signup/ Manager isn't available; 'auth.User' has been swapped for 'users.User'

Setting.Py:

AUTH_USER_MODEL = 'users.User'

LOGOUT_REDIRECT_URL = '/'
LOGIN_REDIRECT_URL = '/'

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'users.backends.EmailBackend',
)

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts',
'avatar',
'homepage',
'products',`enter code here`
#user part
'users',
]

user/models.py:

from django.db import models
from django.contrib.auth.models import AbstractUser
from django.contrib.auth import get_user_model

class User(AbstractUser):
nickname = models.CharField(max_length = 50, blank = True)

class Meta(AbstractUser.Meta):
pass

accounts/models.py:

from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import User

from django.conf import settings
User= settings.AUTH_USER_MODEL

class Profile(models.Model):
"""
Define model for user profile with one-to-one relationship with User table.
"""
user = models.OneToOneField(User, on_delete=models.CASCADE)
phone_number = models.CharField(max_length=20, blank=True)
#country = CountryField(blank=True)
about = models.TextField(max_length=500, blank=True)

# Define signals to update user profile whenever we create/update User model.
@rece
iver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
"""
Create Profile object whenever new User object is created.
"""
if created:
Profile.objects.create(user=instance)

@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
"""
Update Profile object whenever new User object is updated.
"""
instance.profile.save()

最佳答案

AUTH_USER_MODEL = 'users.User'

INSTALLED_APPS = [
...,
'users',
]

user/models.py:

这应该是用户

删除:

from django.contrib.auth.models import User

来自accounts/models.py

关于python - 经理不在; 'auth.User' 已替换为 'users.User',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58310159/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com