def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
messages.success(request, f'Создан аккаунт {username}!')
return redirect('login')
else:
form = UserCreationForm()
return render(request, 'register.html', {'form': form})