modern-django-starter/django_project/settings/production.py
Django Template 2c277d13f6 Fix Django logging configuration for Docker containers
## Issue Fixed:
- Django production logging was trying to write to `/var/log/django/django.log`
- This directory doesn't exist in Docker containers, causing deployment failures
- Error: `FileNotFoundError: [Errno 2] No such file or directory: '/var/log/django/django.log'`

## Solution:
- **Modified production.py**: Switched from file-based to console-only logging
- **Docker-friendly logging**: All logs now go to stdout/stderr for container compatibility
- **Dokploy integration**: Logs are now visible in Dokploy's log viewer
- **Added troubleshooting**: Updated DOKPLOY.md with this specific error and solution

## Benefits:
-  Works seamlessly with Docker containers
-  Integrates with Dokploy log viewing system
-  No file permissions or directory creation issues
-  Standard practice for containerized applications

This fixes the deployment failure identified in the Dokploy logs.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-11 16:19:38 +05:30

61 lines
1.5 KiB
Python

"""
Production settings for Django project.
"""
from .base import *
DEBUG = False
ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=lambda v: [s.strip() for s in v.split(',')])
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_SECONDS = 31536000
SECURE_REDIRECT_EXEMPT = []
SECURE_SSL_REDIRECT = config('SECURE_SSL_REDIRECT', default=False, cast=bool)
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
USE_TZ = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
SECURE_HSTS_PRELOAD = True
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
'style': '{',
},
'simple': {
'format': '{levelname} {message}',
'style': '{',
},
},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
},
'root': {
'handlers': ['console'],
'level': 'INFO',
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'INFO',
'propagate': False,
},
'django.request': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': False,
},
},
}