diff --git a/apps/core/management/__init__.py b/apps/core/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/core/management/commands/__init__.py b/apps/core/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/core/management/commands/debug_settings.py b/apps/core/management/commands/debug_settings.py new file mode 100644 index 0000000..b0feeb3 --- /dev/null +++ b/apps/core/management/commands/debug_settings.py @@ -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!') diff --git a/django_project/settings/production.py b/django_project/settings/production.py index 71f7164..f3e0ce1 100644 --- a/django_project/settings/production.py +++ b/django_project/settings/production.py @@ -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 diff --git a/entrypoint.sh b/entrypoint.sh index 7ab06ab..964d4ac 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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