This is related to this post. Opposite requirement. I want the form to show email, first_name and last_name too.
class SignUp(generic.CreateView):
form_class = UserCreationForm
fields = ['username', 'password1', 'password2', 'email', 'first_name', 'last_name']
success_url = reverse_lazy('dashboard')
template_name = 'registration/signup.html'
def form_valid(self, form):
view = super(SignUp, self).form_valid(form)
username, password, email = form.cleaned_data.get('username'), form.cleaned_data.get('password1'), form.cleaned_data.get('email')
user = authenticate(username=username, password=password, email=email)
login(self.request, user)
return view
But I get
Specifying both ‘fields’ and ‘form_class’ is not permitted.
-
email should be unique.
-
What if I want some additional custom fields with custom validation ? Create
class UserCreationForm(UserCreationForm):
in forms.py ?