I am trying to allow users create an account from without using the from django.forms import UserCreationForm. I just want the users to use just the input field and i can grab unto what ever they are passing into the input field and create an account for them.
This is the django forms for creating users with UserCreationForm, how do i now do the same but without the UserCreationForm?
views.py
def RegisterView(request):
if request.method == "POST":
form = UserRegisterForm(request.POST or None)
if form.is_valid():
new_user = form.save()
username = form.cleaned_data.get('email')
messages.success(request, f'Account Created')
new_user = authenticate(username=form.cleaned_data['email'],
password=form.cleaned_data['password1'],)
login(request, new_user)
return redirect('index')
elif request.user.is_authenticated:
return redirect('index')
else:
form = UserRegisterForm()
context = {
'form': form,
}
return render(request, 'userauths/sign-up.html', context)
forms.py
from django.contrib.auth.forms import UserCreationForm
from userauths.models import User
class UserRegisterForm(UserCreationForm):
class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']