You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
676 B
18 lines
676 B
from django.shortcuts import render, redirect
|
|
from django.contrib.auth.forms import UserCreationForm
|
|
from django.contrib.auth import login, authenticate
|
|
|
|
def register(request):
|
|
if request.method == 'POST':
|
|
form = UserCreationForm(request.POST)
|
|
if form.is_valid():
|
|
form.save()
|
|
username = form.cleaned_data.get('username')
|
|
password = form.cleaned_data.get('password1')
|
|
user = authenticate(username=username, password=password)
|
|
login(request, user)
|
|
return redirect('index')
|
|
else:
|
|
form = UserCreationForm()
|
|
return render(request, 'accounts/register.html', {'form': form})
|