Spaces:
Sleeping
Sleeping
Fix CSRF error and add automatic superuser creation
Browse files- Dockerfile +2 -1
- create_superuser.py +18 -0
- satcap_project/settings.py +4 -0
Dockerfile
CHANGED
|
@@ -26,8 +26,9 @@ COPY . /app/
|
|
| 26 |
# Create media and static directories
|
| 27 |
RUN mkdir -p /app/media /app/static
|
| 28 |
|
| 29 |
-
# Run migrations and collectstatic
|
| 30 |
RUN python manage.py migrate
|
|
|
|
| 31 |
RUN python manage.py collectstatic --noinput
|
| 32 |
|
| 33 |
# Expose the port Gradio/Hugging Face expects
|
|
|
|
| 26 |
# Create media and static directories
|
| 27 |
RUN mkdir -p /app/media /app/static
|
| 28 |
|
| 29 |
+
# Run migrations, create superuser and collectstatic
|
| 30 |
RUN python manage.py migrate
|
| 31 |
+
RUN python create_superuser.py
|
| 32 |
RUN python manage.py collectstatic --noinput
|
| 33 |
|
| 34 |
# Expose the port Gradio/Hugging Face expects
|
create_superuser.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import django
|
| 3 |
+
|
| 4 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'satcap_project.settings')
|
| 5 |
+
django.setup()
|
| 6 |
+
|
| 7 |
+
from django.contrib.auth import get_user_model
|
| 8 |
+
|
| 9 |
+
User = get_user_model()
|
| 10 |
+
username = os.environ.get('DJANGO_SUPERUSER_USERNAME', 'admin')
|
| 11 |
+
email = os.environ.get('DJANGO_SUPERUSER_EMAIL', 'admin@example.com')
|
| 12 |
+
password = os.environ.get('DJANGO_SUPERUSER_PASSWORD', 'admin123')
|
| 13 |
+
|
| 14 |
+
if not User.objects.filter(username=username).exists():
|
| 15 |
+
print(f"Creating superuser {username}...")
|
| 16 |
+
User.objects.create_superuser(username, email, password)
|
| 17 |
+
else:
|
| 18 |
+
print(f"Superuser {username} already exists.")
|
satcap_project/settings.py
CHANGED
|
@@ -96,5 +96,9 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
|
| 96 |
|
| 97 |
CORS_ALLOW_ALL_ORIGINS = True # For development
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
MEDIA_URL = '/media/'
|
| 100 |
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
|
|
|
| 96 |
|
| 97 |
CORS_ALLOW_ALL_ORIGINS = True # For development
|
| 98 |
|
| 99 |
+
CSRF_TRUSTED_ORIGINS = [
|
| 100 |
+
"https://cosmolabhub-satcap-oceans-docker.hf.space",
|
| 101 |
+
]
|
| 102 |
+
|
| 103 |
MEDIA_URL = '/media/'
|
| 104 |
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|