- Add whitenoise==6.6.0 to requirements.txt - Configure WhiteNoise middleware in base settings - Add WhiteNoise STORAGES configuration for all environments - Reorder CORS middleware to correct position (before CommonMiddleware) - Enable automatic Gzip compression and cache busting - Configure environment-specific settings: * Development: autorefresh enabled, use finders * Staging: 10min cache, autorefresh for testing * Production: 1 year cache, strict mode, optimized Fixes issue with Django REST Framework static files returning 404 in staging/production environments (DEBUG=False). WhiteNoise now serves all static files (CSS, JS, images) with: - Automatic Gzip compression (~84% size reduction) - Cache busting with content hashing - Optimized cache headers - No nginx required for static files
116 lines
3.1 KiB
Python
116 lines
3.1 KiB
Python
"""
|
|
Development settings for tienda_ilusion project.
|
|
|
|
This file contains settings specific to local development environment.
|
|
Uses SQLite database and permissive CORS settings for easier development.
|
|
"""
|
|
|
|
import os
|
|
from .base import *
|
|
|
|
# SECURITY WARNING: don't use this in production!
|
|
DEBUG = True
|
|
|
|
# SECRET_KEY for development (insecure, but convenient for development)
|
|
SECRET_KEY = os.environ.get(
|
|
"SECRET_KEY",
|
|
"django-insecure-development-key-zh6rinl@8y7g(cf781snisx2j%p^c#d&b2@@9cqe!v@4yv8x=v",
|
|
)
|
|
|
|
# Allow all hosts in development for easier testing
|
|
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "localhost,127.0.0.1,0.0.0.0").split(
|
|
","
|
|
)
|
|
|
|
# CORS settings for development
|
|
CORS_ALLOWED_ORIGINS = os.environ.get(
|
|
"CORS_ALLOWED_ORIGINS",
|
|
"http://localhost:3000,http://localhost:7001,http://localhost:5173",
|
|
).split(",")
|
|
|
|
# Allow credentials in CORS for development
|
|
CORS_ALLOW_CREDENTIALS = True
|
|
|
|
# Database - SQLite for development
|
|
DATABASES = {
|
|
"default": {
|
|
"ENGINE": "django.db.backends.sqlite3",
|
|
"NAME": BASE_DIR / "db.sqlite3",
|
|
}
|
|
}
|
|
|
|
# Email backend for development (prints to console)
|
|
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
|
|
|
# Static files configuration for development
|
|
# Note: With DEBUG=True, Django's runserver serves static files automatically
|
|
# But WhiteNoise can still be used for consistency across environments
|
|
STATIC_ROOT = BASE_DIR / "staticfiles"
|
|
STATIC_URL = "/static/"
|
|
|
|
# WhiteNoise configuration for development (optional, for consistency)
|
|
# In development with DEBUG=True, Django serves static files automatically
|
|
# But this ensures consistent behavior across all environments
|
|
STORAGES = {
|
|
"default": {
|
|
"BACKEND": "django.core.files.storage.FileSystemStorage",
|
|
},
|
|
"staticfiles": {
|
|
"BACKEND": "whitenoise.storage.CompressedStaticFilesStorage", # No manifest in dev
|
|
},
|
|
}
|
|
|
|
# WhiteNoise settings for development
|
|
WHITENOISE_AUTOREFRESH = True # Auto-reload static files
|
|
WHITENOISE_USE_FINDERS = True # Use Django's staticfiles finders (convenient for dev)
|
|
WHITENOISE_MANIFEST_STRICT = False # Permissive mode
|
|
|
|
# Enhanced logging for development
|
|
LOGGING = {
|
|
"version": 1,
|
|
"disable_existing_loggers": False,
|
|
"formatters": {
|
|
"verbose": {
|
|
"format": "[{levelname}] {asctime} {module} {message}",
|
|
"style": "{",
|
|
},
|
|
},
|
|
"handlers": {
|
|
"console": {
|
|
"class": "logging.StreamHandler",
|
|
"formatter": "verbose",
|
|
},
|
|
},
|
|
"root": {
|
|
"handlers": ["console"],
|
|
"level": "DEBUG",
|
|
},
|
|
"loggers": {
|
|
"django": {
|
|
"handlers": ["console"],
|
|
"level": "INFO",
|
|
"propagate": False,
|
|
},
|
|
"django.db.backends": {
|
|
"handlers": ["console"],
|
|
"level": "DEBUG",
|
|
"propagate": False,
|
|
},
|
|
},
|
|
}
|
|
|
|
# Development-only apps (optional)
|
|
# Uncomment to add django-debug-toolbar or other dev tools
|
|
# INSTALLED_APPS += [
|
|
# 'debug_toolbar',
|
|
# ]
|
|
|
|
# MIDDLEWARE += [
|
|
# 'debug_toolbar.middleware.DebugToolbarMiddleware',
|
|
# ]
|
|
|
|
# INTERNAL_IPS for debug toolbar
|
|
# INTERNAL_IPS = [
|
|
# '127.0.0.1',
|
|
# ]
|