mirror of
https://github.com/thecyberlearn/modern-django-starter.git
synced 2026-08-18 07:52:54 +00:00
Add debugging for environment variables and Django settings
- Fix production.py settings to properly read environment variables with defaults - Add debug_settings management command to troubleshoot environment variable issues - Add debugging output to entrypoint.sh to see what settings are loaded - This will help identify why ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS may not be working
This commit is contained in:
parent
31ab604b7c
commit
23f9778964
0
apps/core/management/__init__.py
Normal file
0
apps/core/management/__init__.py
Normal file
0
apps/core/management/commands/__init__.py
Normal file
0
apps/core/management/commands/__init__.py
Normal file
44
apps/core/management/commands/debug_settings.py
Normal file
44
apps/core/management/commands/debug_settings.py
Normal file
@ -0,0 +1,44 @@
|
||||
import os
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Debug Django settings and environment variables'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS('🔍 Debug Information for Django Settings')
|
||||
)
|
||||
|
||||
# Check environment variables
|
||||
env_vars = [
|
||||
'DJANGO_SETTINGS_MODULE',
|
||||
'DEBUG',
|
||||
'ALLOWED_HOSTS',
|
||||
'CSRF_TRUSTED_ORIGINS',
|
||||
'SECRET_KEY',
|
||||
'SECURE_SSL_REDIRECT',
|
||||
]
|
||||
|
||||
self.stdout.write('\n📝 Environment Variables:')
|
||||
for var in env_vars:
|
||||
value = os.environ.get(var, 'NOT SET')
|
||||
if var == 'SECRET_KEY' and value != 'NOT SET':
|
||||
value = f"{value[:10]}...***" # Hide secret key
|
||||
self.stdout.write(f" {var} = {value}")
|
||||
|
||||
# Check Django settings
|
||||
self.stdout.write('\n⚙️ Django Settings:')
|
||||
try:
|
||||
self.stdout.write(f" DEBUG = {settings.DEBUG}")
|
||||
self.stdout.write(f" ALLOWED_HOSTS = {settings.ALLOWED_HOSTS}")
|
||||
self.stdout.write(f" CSRF_TRUSTED_ORIGINS = {getattr(settings, 'CSRF_TRUSTED_ORIGINS', 'NOT SET')}")
|
||||
self.stdout.write(f" SECURE_SSL_REDIRECT = {getattr(settings, 'SECURE_SSL_REDIRECT', 'NOT SET')}")
|
||||
self.stdout.write(f" SETTINGS MODULE = {settings.SETTINGS_MODULE}")
|
||||
except Exception as e:
|
||||
self.stdout.write(
|
||||
self.style.ERROR(f"Error reading settings: {e}")
|
||||
)
|
||||
|
||||
self.stdout.write('\n✅ Debug completed!')
|
||||
@ -3,9 +3,13 @@ Production settings for Django project.
|
||||
"""
|
||||
from .base import *
|
||||
|
||||
DEBUG = False
|
||||
DEBUG = config('DEBUG', default=False, cast=bool)
|
||||
|
||||
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=lambda v: [s.strip() for s in v.split(',')])
|
||||
# Override ALLOWED_HOSTS with production default if not set
|
||||
ALLOWED_HOSTS = config('ALLOWED_HOSTS', default='localhost,127.0.0.1', cast=lambda v: [s.strip() for s in v.split(',')])
|
||||
|
||||
# CSRF trusted origins for production (inherits from base.py but can be overridden)
|
||||
CSRF_TRUSTED_ORIGINS = config('CSRF_TRUSTED_ORIGINS', default='', cast=lambda v: [s.strip() for s in v.split(',') if s.strip()])
|
||||
|
||||
SECURE_BROWSER_XSS_FILTER = True
|
||||
SECURE_CONTENT_TYPE_NOSNIFF = True
|
||||
|
||||
@ -24,6 +24,9 @@ python manage.py setup_social_apps || {
|
||||
echo "Skipping Tailwind build at runtime (already built during Docker build)..."
|
||||
# Note: Tailwind CSS is built during the Docker build process to avoid permission issues
|
||||
|
||||
echo "🔍 Debugging Django settings..."
|
||||
python manage.py debug_settings
|
||||
|
||||
echo "Collecting static files..."
|
||||
# Handle potential permission issues with Docker volumes
|
||||
# Try to collect static files, but don't fail if it doesn't work since we have build-time static files
|
||||
|
||||
Loading…
Reference in New Issue
Block a user