SATCAP-OCEANS_DOCKER / create_superuser.py
rinogeek's picture
Fix CSRF error and add automatic superuser creation
752f799
raw
history blame contribute delete
611 Bytes
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'satcap_project.settings')
django.setup()
from django.contrib.auth import get_user_model
User = get_user_model()
username = os.environ.get('DJANGO_SUPERUSER_USERNAME', 'admin')
email = os.environ.get('DJANGO_SUPERUSER_EMAIL', 'admin@example.com')
password = os.environ.get('DJANGO_SUPERUSER_PASSWORD', 'admin123')
if not User.objects.filter(username=username).exists():
print(f"Creating superuser {username}...")
User.objects.create_superuser(username, email, password)
else:
print(f"Superuser {username} already exists.")