我正在尝试创建一个登录视图,该视图将允许用户登录他们的个人资料。但是即使他们是对的,它也永远不会登录。我尝试了很多其他方法,例如更改模型来更改AUTH_USER_MODEL,但似乎无济于事
在这里,是models.py
class UserProfile(models.Model):
user = models.OneToOneField(User,null = True)
username = models.CharField(max_length = 30,unique = False)
email = models.EmailField(max_length = 50)
password = models.CharField(max_length = 20)
confirm_password = models.CharField(max_length = 20)
profession = models.CharField(max_length = 50)
def __str__(self):
return self.user.username
在这里是用于登录的views.py
def login(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('Password')
user = authenticate(username = username,password = password)
if user:
if user.is_active:
login(request,user)
return HttpResponseRedirect('/profile/')
else:
return HttpResponse('User no longer active')
else:
print(f'username :{username}')
return render(request,'social_app/login.html')