картинки в одну высоту, добавил вывод времени
All checks were successful
Auto-Deploy-Shop / deploy (push) Successful in 7s
All checks were successful
Auto-Deploy-Shop / deploy (push) Successful in 7s
генерации и переменной среды
This commit is contained in:
55
scripts/init_project.ps1
Normal file
55
scripts/init_project.ps1
Normal file
@@ -0,0 +1,55 @@
|
||||
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"
|
||||
Reference in New Issue
Block a user