feat: добавить поддержку Whitenoise и обновить конфигурацию для продакшна
All checks were successful
Build and Push Docker Image / build (push) Successful in 25s

- Добавлен Whitenoise для управления статическими файлами
- Настроены STATICFILES_DIRS, STATIC_ROOT и STORAGES
- Добавлен middleware Whitenoise
- Обновлён Dockerfile: добавлена команда collectstatic
- Включён preview host в ALLOWED_HOSTS
- Добавлены необходимые зависимости в requirements.txt
This commit is contained in:
2026-03-30 22:50:29 +02:00
parent 6dcdccf801
commit c367831df8
3 changed files with 24 additions and 1 deletions

View File

@@ -7,6 +7,8 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN python manage.py collectstatic --noinput
ENV HOST=0.0.0.0
ENV PORT=8000

View File

@@ -1,2 +1,3 @@
django
uvicorn
whitenoise

View File

@@ -24,7 +24,9 @@ SECRET_KEY = 'django-insecure-*%u*i415=%@ny05mbd-j3802bcl!(0nwa3#^yxnor)7nd(w7%q
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
ALLOWED_HOSTS = [
"https://preview-1.azimkin.dev"
]
# Application definition
@@ -35,10 +37,15 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'home',
'items',
'orders',
'users',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
@@ -117,6 +124,19 @@ STATICFILES_DIRS = [
BASE_DIR / 'static',
]
# Where collectstatic collects files for production
STATIC_ROOT = BASE_DIR / 'staticfiles'
# Whitenoise storage for compressed static files
STORAGES = {
'default': {
'BACKEND': 'django.core.files.storage.FileSystemStorage',
},
'staticfiles': {
'BACKEND': 'whitenoise.storage.CompressedManifestStaticFilesStorage',
},
}
# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field