gpt4 book ai didi

django - 属性错误 : 'User' object has no attribute 'check_password' error in Django?

转载 作者:行者123 更新时间:2023-12-01 11:46:40 28 4
gpt4 key购买 nike

我有一个自定义模型,我正在尝试对其进行身份验证:

class User(models.Model):
#id = models.IntegerField(primary_key=True)
#identifier = models.CharField(max_length=40, unique=True, db_index=True)
username = models.CharField(max_length=90, unique=True, db_index=True)
create_time = models.DateTimeField(null=True, blank=True)
update_time = models.DateTimeField(null=True, blank=True)
email = models.CharField(max_length=225)
password = models.CharField(max_length=120)
external = models.IntegerField(null=True, blank=True)
deleted = models.IntegerField(null=True, blank=True)
purged = models.IntegerField(null=True, blank=True)
form_values_id = models.IntegerField(null=True, blank=True)
disk_usage = models.DecimalField(null=True, max_digits=16, decimal_places=0, blank=True)
#last_login = models.DateTimeField()

objects = UserManager()
USERNAME_FIELD = 'username'
#check_password(password)
class Meta:
db_table = u'galaxy_user'

我在“设置”中提到过这一点。

AUTH_USER_MODEL = 'fileupload.user'

 #views.py
def login_backend(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return HttpResponseRedirect('/overview/')
else:
return HttpResponseRedirect('/login_backend/')
else:
return render_to_response('login_backend.html', context_instance=RequestContext(request))

但是我收到了这个错误:

AttributeError: 'User' object has no attribute 'check_password' error 

我做错了什么?

最佳答案

custom user documentation 中所述,您的用户模型必须继承自 django.contrib.auth.models.AbstractBaseUser,它添加了所有相关方法。

关于django - 属性错误 : 'User' object has no attribute 'check_password' error in Django?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14726028/

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