photo26/signup/views.py
aeltheos 2db323f74d inital commit for signup
added a basic app using the UserCreationForm to create new user at /accounts/signup/
change outside of the app are:
-added signup to INSTALLED_APPS in /photo21/settings.py
-added accounts/signup/ to path in /photo21/urls.py

should extend UserCreationForm to have field for email and maybe first/last names, except if we want the user to add that themselves later
2021-10-07 16:59:16 +02:00

19 lines
No EOL
640 B
Python

from django import forms
from django.contrib.auth import login
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
def signup(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
user = form.save()
login(request, user)
return redirect('/')
return render(request,'signup.html', {'form':form})
else:
form = UserCreationForm()
return render(request,'signup.html', {'form':form})