简体   繁体   English

UserCreationForm没有字段用户名

[英]UserCreationForm has no field username

When i have this View, it gives me error, that UserCreationForm has no attribute username why? 当我有此视图时,它给我错误,UserCreationForm没有属性用户名,为什么? I thouught that UserCreationForm has username field in it 我认为UserCreationForm中包含用户名字段

if request.method == 'POST': # If the form has been submitted...
                username_a_heslo = UserCreationForm(request.POST, prefix = "začátek")
                přidat_údaje = UcitelZmenaForm(request.POST, prefix = "konec")
                if username_a_heslo.is_valid() and přidat_údaje.is_valid(): # All validation rules pass
                    owner = request.user
                    owner.username = username_a_heslo.username
                    owner.save()
                    zmenahesla=request.user.set_password(username_a_heslo.password)
                    # primary = username_a_heslo.save()
                    přidat_údaje.cleaned_data["primary"] = primary
                    cast_form = Ucitel.objects.all().filter(user=request.user)
                    form = UcitelZmenaForm(přidat_údaje, instance=cast_form[0])
                    a=form.save
                    #b = přidat_údaje.save()
                    return HttpResponseRedirect('/hlavni_stranka/')
            else:
                username_a_heslo = UserCreationForm(prefix = "začátek")
                přidat_údaje = UcitelZmenaForm(prefix = "konec")
            return render(request, 'registration/prihlasen.html', {'prvni_prihlaseni':prvni_prihlaseni,'první_form': username_a_heslo,'druhý_form':přidat_údaje})

username is a field, not an attribute on the form. username是一个字段,而不是表单上的属性。 It's in the cleaned_data dict, just like you do with primary further down. 它位于cleaned_data dict中,就像您对primary进一步处理一样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 'UserCreationForm'对象没有属性'get_username'django 1.8 - 'UserCreationForm' object has no attribute 'get_username' django 1.8 如何从 Django 的 UserCreationForm 中的用户名字段禁用自动对焦? - How to disable autofocus from username field in Django's UserCreationForm? 如何在 Django 的 UserCreationForm 中扩展字段? - How to extend field in UserCreationForm in django? '具有该用户名的用户已经存在'不在 Django UserCreationForm 中了吗? - 'a user with that username already exists' is not in Django UserCreationForm anymore? 如何删除 django UserCreationForm 中的密码确认字段 - How to remove password confirmation field in django UserCreationForm 'UserCreationForm'对象在Django中没有属性'FormWrapper' - 'UserCreationForm' object has no attribute 'FormWrapper' in Django 在 Django 的 UserCreationForm 中添加“日期字段”并将其连接到 model - Add "Date field" in UserCreationForm in Django and connect it to model 如何在Django的UserCreationForm / User Model中将客户的电子邮件作为用户名? - How to make customer's email as the username in UserCreationForm / User Model in Django? FieldDoesNotExist at /accounts/signup/,用户没有名为“用户名”的字段 - FieldDoesNotExist at /accounts/signup/, User has no field named 'username' AttributeError: 类型对象“User”没有属性“USERNAME_FIELD” - AttributeError: type object 'User' has no attribute 'USERNAME_FIELD'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM