views.py
def signup(request):
msg = None
if request.method == 'POST':
form = SignupForm(request.POST)
if form.is_valid():
user = form.save()
msg = 'user created'
return redirect('login')
else:
msg = 'form is not valid'
else:
form = SignupForm()
return render(request, 'signup.html', {'form': form, 'msg': msg})
forms.py
from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import User
class SignupForm(UserCreationForm):
fullname = forms.CharField(
widget=forms.TextInput(
attrs={
"class":"form-control"
}
)
)
email = forms.CharField(
widget=forms.EmailInput(
attrs={
"class": "form-control"
}
)
)
username = forms.CharField(
widget=forms.TextInput(
attrs={
"class": "form-control"
}
)
)
password = forms.CharField(
widget=forms.PasswordInput(
attrs={
"class": "form-control"
}
)
)
cpassword = forms.CharField(
widget=forms.PasswordInput(
attrs={
"class": "form-control"
}
)
)
city = forms.CharField(
widget=forms.TextInput(
attrs={
"class": "form-control"
}
)
)
class LoginForm(forms.Form):
username = forms.CharField(
widget=forms.TextInput(
attrs={
"class": "form-control"
}
)
)
password = forms.CharField(
widget=forms.PasswordInput(
attrs={
"class": "form-control"
}
)
)
class Meta:
model = User
fields = ('fullname','username','email','city','password','cpassword')
models.py
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.
class User(AbstractUser):
is_admin=models.BooleanField('Is Admin',default=False)
is_customer=models.BooleanField('Is Customer',default=True)
setting.py
AUTH_USER_MODEL =‘account.User’