extended UserCreationForm to RegistrationForm, adding fields for email/firstname/lastname
This commit is contained in:
parent
aeb9cafd40
commit
ecc80b939d
2 changed files with 18 additions and 4 deletions
|
|
@ -4,16 +4,18 @@ from django.http.response import HttpResponse
|
|||
|
||||
|
||||
from django.shortcuts import redirect, render
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from django.contrib.auth.models import User
|
||||
from .forms import RegistrationForm
|
||||
def signup(request):
|
||||
if request.method == 'POST':
|
||||
form = UserCreationForm(request.POST)
|
||||
form = RegistrationForm(request.POST)
|
||||
if form.is_valid():
|
||||
user = form.save()
|
||||
user.first_name = form.cleaned_data.get('first_name')
|
||||
user.last_name = form.cleaned_data.get('last_name')
|
||||
user.email = form.cleaned_data.get('email')
|
||||
login(request, user)
|
||||
return redirect('/')
|
||||
return render(request,'signup.html', {'form':form})
|
||||
else:
|
||||
form = UserCreationForm()
|
||||
form = RegistrationForm()
|
||||
return render(request,'signup.html', {'form':form})
|
||||
Loading…
Add table
Add a link
Reference in a new issue