maybe late, but that was exactly my question, and after several hours of struggle, they finally found out.
You may have found, but if other people are looking for a solution, here's mine.
You just need to override form_valid() in your class CreateView Inheritance. Here is an example with my own class:
class CreateArtistView(CreateView): template_name = 'register.html' form_class = CreateArtistForm success_url = '/' def form_valid(self, form): valid = super(CreateArtistView, self).form_valid(form) username, password = form.cleaned_data.get('username'), form.cleaned_data.get('password1') new_user = authenticate(username=username, password=password) login(self.request, new_user) return valid
I will first catch the value of the method of my parent class form_valid() in valid , because when you call it, it calls form.save (), which registers your user in the database and populates your user self.object .
After that, I had a big problem with my authentication, returning None . This is because I called authenticate() with the django hashed password and authenticated the hash again.
Explaining this, you understand why I use form.cleaned_data.get('username') , and not self.object.username .
I hope this helps you or another, as I have not found a clear answer on the net.
source share