Question

When i have this View, it gives me error, that UserCreationForm has no attribute username why? I thouught that UserCreationForm has username field in it

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})
Was it helpful?

Solution

username is a field, not an attribute on the form. It's in the cleaned_data dict, just like you do with primary further down.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top