Down here I'm trying to create a custom user registration form and this is the error I keep getting: 
That is the result of me using UserCreationForm in place of forms.ModelForm according to many sources.
I tried setting USERNAME_FIELD = username but it said
The field 'username' clashes with the field 'username' from model 'members.user' Before I switched to UserCreationForm the registration did not even create any new user. I successfully created the login functionality, but failed when it came to the registration. It did not show any response after registration form submission.
My code is as followed:
members/models.py
class User(models.Model): username = models.CharField(max_length=50, error_messages=login_errors_mess) password = models.CharField(max_length=50, error_messages=password_errors_mess) members/forms.py
class RegisterForm(UserCreationForm): class Meta: model = User fields = [ 'username', 'password', ] widgets = { 'username': forms.TextInput(attrs={ 'class': 'form-control', 'data-val': 'true', 'data-val-required': 'Please enter your user name'}), 'password': forms.TextInput(attrs={ 'class': 'form-control', 'data-val': 'true', 'data-val-required': 'Please enter your password' }), } members/views.py
def register(request): form = RegisterForm() if request.method == "POST": form = RegisterForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('login') # return redirect('login') form = RegisterForm() return render (request, "registration/register.html", context={"form": form}) templates/registration/register.html
<form method="POST" action="/register/"> {% csrf_token %} {% comment %} {{ form }} {% endcomment %} <div class="form-group"> <label for="username">Username</label> <input type="text" class="form-control" name="username" id="username"/> </div> <div class="form-group"> <label for="password">Password</label> <input type="password" class="form-control" name="password" id="password"/> </div> <button type="submit" class="btn btn-primary btn-flat m-b-30 m-t-30">Register</button> </form> urls.py
urlpatterns = [ path('members/', include('members.urls')), path('admin/', admin.site.urls), path('', dashboard, name='dashboard'), path('register/', register, name='register'), path('login/', login_page, name='login'), ] Could you show me how to solve this? Thank you!