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
This commit is contained in:
amitrana01 2025-09-11 18:02:06 +05:30
parent aa94261cb8
commit 31ab604b7c
4 changed files with 14 additions and 5 deletions

View File

@ -1,7 +1,7 @@
# Django Configuration # Django Configuration
SECRET_KEY=your-secret-key-here-make-it-long-and-random SECRET_KEY=your-secret-key-here-make-it-long-and-random
DEBUG=True DEBUG=False
ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0 ALLOWED_HOSTS=dt.netcoptech.com,localhost,127.0.0.1,0.0.0.0
# Database Configuration # Database Configuration
# Option 1: Individual variables (for Docker Compose/local development) # 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 GOOGLE_OAUTH2_CLIENT_SECRET=your-google-client-secret
# Production SSL Settings (set to True in production) # 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 (optional - for error tracking in production)
SENTRY_DSN=your-sentry-dsn-here SENTRY_DSN=your-sentry-dsn-here

View File

@ -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(',')]) 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_APPS = [
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',

View File

@ -25,7 +25,7 @@ services:
- dokploy-network - dokploy-network
labels: labels:
- "traefik.enable=true" - "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.entrypoints=websecure"
- "traefik.http.routers.django-app.tls.certResolver=letsencrypt" - "traefik.http.routers.django-app.tls.certResolver=letsencrypt"
- "traefik.http.services.django-app.loadbalancer.server.port=8000" - "traefik.http.services.django-app.loadbalancer.server.port=8000"

View File

@ -20,9 +20,14 @@
}, },
{ {
"key": "ALLOWED_HOSTS", "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" "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", "key": "DB_NAME",
"value": "django_db", "value": "django_db",