Django表单清理数据“太多值以解压缩”错误

时间:2022-04-08 16:49:10

I have a very simple login form :

我有一个非常简单的登录表单:

class LoginForm(forms.Form):
    username = forms.CharField(max_length=100,required = True)
    password = forms.CharField(widget = forms.PasswordInput(),max_length=100,required = True)

I am using it following way in the views :

我在视图中按照以下方式使用它:

def login(request):
 msg = []
 form = LoginForm()
 if request.method == 'POST':
    form = LoginForm(request.POST)
    if form.is_valid():
       username = form.cleaned_data['username']
       password = form.cleaned_data['password']    
       user = authenticate(username = username, password = password)

I get the error too many values to unpack. What am I doing wrong ? If you need any more information please comment.

我得到错误太多的值来解压缩。我究竟做错了什么 ?如果您需要更多信息,请发表评论。

1 个解决方案

#1


1  

there might be a problem in the password. reset the password and try again

密码可能有问题。重置密码,然后重试

python manage.py shell
>> from django.contrib.auth.models import User
>> u = User.objects.get(username="myuser")
>> u.set_password("mypassword")
>> u.save()

or delete the db, and made syncdb again(python manage.py syncdb), creating new superuser.

或删除db,并再次生成syncdb(python manage.py syncdb),创建新的超级用户。

#1


1  

there might be a problem in the password. reset the password and try again

密码可能有问题。重置密码,然后重试

python manage.py shell
>> from django.contrib.auth.models import User
>> u = User.objects.get(username="myuser")
>> u.set_password("mypassword")
>> u.save()

or delete the db, and made syncdb again(python manage.py syncdb), creating new superuser.

或删除db,并再次生成syncdb(python manage.py syncdb),创建新的超级用户。