-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsgi.py
More file actions
48 lines (37 loc) · 1.54 KB
/
wsgi.py
File metadata and controls
48 lines (37 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
WSGI config for amc_tracker project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
"""
import os
import sys
import time
from pathlib import Path
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'amc_tracker.settings')
application = get_wsgi_application()
# Auto-run setup_render command on Render
if os.environ.get('RENDER'):
from django.core.management import call_command
# Add the project directory to the Python path
BASE_DIR = Path(__file__).resolve().parent.parent
if str(BASE_DIR) not in sys.path:
sys.path.append(str(BASE_DIR))
# Wait a bit for database to be ready
print("Waiting for services to be ready...")
time.sleep(10)
try:
# Use our custom setup_render command which handles database connection issues
call_command('setup_render', interactive=False)
print("✅ Render setup completed successfully!")
except Exception as e:
print(f"❌ Error during automatic setup: {e}")
# Try to create static directory as a fallback
try:
static_dir = os.path.join(BASE_DIR, 'static')
if not os.path.exists(static_dir):
os.makedirs(static_dir)
print(f"✅ Created static directory at {static_dir}")
except Exception as static_error:
print(f"❌ Error creating static directory: {static_error}")