I think, password needs to be hashed properly, as raw passwords aren't stored by django.
You can make use of cleaned_data
,and you need to hash the password properly, so you can use make_password()
from from django.contrib.auth.hashers import make_password
.
So, with your current code do following modifications in views.py
.
from django.contrib.auth.models import User
from django.contrib.auth.hashers import make_password
def register(request, self):
if request.method == 'POST':
form = CustomUserForm(request.POST)
if form.is_valid():
username=form.cleaned_data['username']
email=form.cleaned_data['email']
password=make_password(form.cleaned_data['password1'])
data=User(username=username,email=email,password=password)
data.save()
messages.success(request, "Registered Successfully")
return redirect('/login/')
else: #Here GET condition
form = CustomUserForm()
context = {'form': form}
return render(request, 'auth/register.html', context)
Note:
You must give/
at the end of every route.
* Be the first to Make Comment