feat: добавить поддержку Whitenoise и обновить конфигурацию для продакшна
All checks were successful
Build and Push Docker Image / build (push) Successful in 25s
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:
@@ -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
|
||||
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
django
|
||||
uvicorn
|
||||
whitenoise
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user