[英]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.