From 31ab604b7c88ac5af17af664fd884608271c7045 Mon Sep 17 00:00:00 2001 From: amitrana01 Date: Thu, 11 Sep 2025 18:02:06 +0530 Subject: [PATCH] Add CSRF_TRUSTED_ORIGINS support for domain configuration - Add CSRF_TRUSTED_ORIGINS setting to read from environment variable - Update docker-compose.dokploy.yml with correct domain dt.netcoptech.com - Update dokploy.json with proper domain configuration - Fix 500 error by supporting CSRF trusted origins for production domains --- .env.example | 7 ++++--- django_project/settings/base.py | 3 +++ docker-compose.dokploy.yml | 2 +- dokploy.json | 7 ++++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index defdd00..e89526c 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ # Django Configuration SECRET_KEY=your-secret-key-here-make-it-long-and-random -DEBUG=True -ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0 +DEBUG=False +ALLOWED_HOSTS=dt.netcoptech.com,localhost,127.0.0.1,0.0.0.0 # Database Configuration # Option 1: Individual variables (for Docker Compose/local development) @@ -44,7 +44,8 @@ GOOGLE_OAUTH2_CLIENT_ID=your-google-client-id GOOGLE_OAUTH2_CLIENT_SECRET=your-google-client-secret # Production SSL Settings (set to True in production) -SECURE_SSL_REDIRECT=False +SECURE_SSL_REDIRECT=True +CSRF_TRUSTED_ORIGINS=https://dt.netcoptech.com # Sentry (optional - for error tracking in production) SENTRY_DSN=your-sentry-dsn-here \ No newline at end of file diff --git a/django_project/settings/base.py b/django_project/settings/base.py index 588832c..017663a 100644 --- a/django_project/settings/base.py +++ b/django_project/settings/base.py @@ -13,6 +13,9 @@ DEBUG = config('DEBUG', default=False, cast=bool) 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 +CSRF_TRUSTED_ORIGINS = config('CSRF_TRUSTED_ORIGINS', default='', cast=lambda v: [s.strip() for s in v.split(',') if s.strip()]) + DJANGO_APPS = [ 'django.contrib.admin', 'django.contrib.auth', diff --git a/docker-compose.dokploy.yml b/docker-compose.dokploy.yml index 1cf1000..4d93800 100644 --- a/docker-compose.dokploy.yml +++ b/docker-compose.dokploy.yml @@ -25,7 +25,7 @@ services: - dokploy-network labels: - "traefik.enable=true" - - "traefik.http.routers.django-app.rule=Host(`your-domain.com`)" + - "traefik.http.routers.django-app.rule=Host(`dt.netcoptech.com`)" - "traefik.http.routers.django-app.entrypoints=websecure" - "traefik.http.routers.django-app.tls.certResolver=letsencrypt" - "traefik.http.services.django-app.loadbalancer.server.port=8000" diff --git a/dokploy.json b/dokploy.json index 735603b..26459a8 100644 --- a/dokploy.json +++ b/dokploy.json @@ -20,9 +20,14 @@ }, { "key": "ALLOWED_HOSTS", - "value": "your-domain.com,www.your-domain.com", + "value": "dt.netcoptech.com,localhost,127.0.0.1", "description": "Comma-separated list of allowed hosts" }, + { + "key": "CSRF_TRUSTED_ORIGINS", + "value": "https://dt.netcoptech.com", + "description": "CSRF trusted origins for production" + }, { "key": "DB_NAME", "value": "django_db",