param( [string]$Username = "ack", [string]$Email = "admin@example.com", [string]$Password = "123" ) Write-Host "Initializing project environment..." if (-not (Test-Path ".venv")) { Write-Host "Creating virtual environment .venv..." python -m venv .venv } else { Write-Host "Virtual environment .venv already exists." } $venvPython = Join-Path -Path ".venv" -ChildPath "Scripts\python.exe" $venvPip = Join-Path -Path ".venv" -ChildPath "Scripts\pip.exe" Write-Host "Upgrading pip and installing requirements..." & $venvPython -m pip install --upgrade pip & $venvPip install -r requirements.txt Write-Host "Applying database migrations..." & $venvPython manage.py migrate Write-Host "Collecting static files..." & $venvPython manage.py collectstatic --noinput if (-not $Password) { $secure = Read-Host "Enter superuser password (input hidden)" -AsSecureString $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure) $plainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr) [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstr) } else { $plainPassword = $Password } Write-Host "Creating superuser (if it doesn't exist)..." $createUserPy = @" from django.contrib.auth import get_user_model User = get_user_model() username = '$Username' email = '$Email' password = '$plainPassword' if not User.objects.filter(username=username).exists(): User.objects.create_superuser(username=username, email=email, password=password) print('Superuser created.') else: print('Superuser already exists.') "@ # pipe the python snippet into manage.py shell $createUserPy | & $venvPython manage.py shell Write-Host "Initialization complete. You can now run the development server with: .\.venv\Scripts\python.exe manage.py runserver"