diff --git a/cadpoint/cadpoint/settings.py b/cadpoint/cadpoint/settings.py index 624e862..c93fbd8 100644 --- a/cadpoint/cadpoint/settings.py +++ b/cadpoint/cadpoint/settings.py @@ -57,8 +57,6 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sitemaps', - # Панель отладки показываем только в dev-окружении при `DEBUG=True`. - 'debug_toolbar', 'django_select2', 'easy_thumbnails', 'filer.apps.FilerConfig', @@ -70,8 +68,6 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', - # Middleware нужен, иначе панель debug toolbar просто не влезет в response. - 'debug_toolbar.middleware.DebugToolbarMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -233,3 +229,33 @@ NUM_NAV_ITEMS_IN_PAGE = 7 # Число статей (заголовок + тизер) на странице NUM_ITEMS_IN_PAGE = NUM_NAV_ITEMS_IN_PAGE + +if DEBUG: + # В деве оставляем стандартную отдачу статики Django без WhiteNoise. + STORAGES = { + 'staticfiles': { + 'BACKEND': 'django.contrib.staticfiles.storage.StaticFilesStorage', + }, + } + # Django Debug Toolbar нужен только в dev + def _show_debug_toolbar(request): + """Скрывает debug toolbar внутри админки Django""" + return not request.path.startswith(f'/{ADMIN_URL}') + + INSTALLED_APPS.append('debug_toolbar') + MIDDLEWARE.insert(1, 'debug_toolbar.middleware.DebugToolbarMiddleware') + DEBUG_TOOLBAR_CONFIG = { + 'SHOW_TOOLBAR_CALLBACK': _show_debug_toolbar, + } + +else: + # В проде WhiteNoise обслуживает собранную статику и файлы из `public`. + MIDDLEWARE.insert(1, 'whitenoise.middleware.WhiteNoiseMiddleware') + STORAGES = { + 'staticfiles': { + 'BACKEND': 'whitenoise.storage.CompressedManifestStaticFilesStorage', + }, + } + # Конфигурация WhiteNoise для обслуживания статических файлов и файлов из /public (например, + # robots.txt, favicon.ico и т.п.) + WHITENOISE_ROOT = PUBLIC_DIR diff --git a/poetry.lock b/poetry.lock index 208d075..492f955 100644 --- a/poetry.lock +++ b/poetry.lock @@ -392,6 +392,29 @@ beautifulsoup4 = ">=4.10.0" lxml = ">=4.9.0" regex = ">=2022.1.18" +[[package]] +name = "gunicorn" +version = "25.3.0" +description = "WSGI HTTP Server for UNIX" +optional = false +python-versions = ">=3.10" +files = [ + {file = "gunicorn-25.3.0-py3-none-any.whl", hash = "sha256:cacea387dab08cd6776501621c295a904fe8e3b7aae9a1a3cbb26f4e7ed54660"}, + {file = "gunicorn-25.3.0.tar.gz", hash = "sha256:f74e1b2f9f76f6cd1ca01198968bd2dd65830edc24b6e8e4d78de8320e2fe889"}, +] + +[package.dependencies] +packaging = "*" + +[package.extras] +eventlet = ["eventlet (>=0.40.3)"] +fast = ["gunicorn_h1c (>=0.6.3)"] +gevent = ["gevent (>=24.10.1)"] +http2 = ["h2 (>=4.1.0)"] +setproctitle = ["setproctitle"] +testing = ["coverage", "eventlet (>=0.40.3)", "gevent (>=24.10.1)", "h2 (>=4.1.0)", "httpx[http2]", "pytest", "pytest-asyncio", "pytest-cov", "uvloop (>=0.19.0)"] +tornado = ["tornado (>=6.5.0)"] + [[package]] name = "lxml" version = "6.0.2" @@ -547,6 +570,17 @@ html-clean = ["lxml_html_clean"] html5 = ["html5lib"] htmlsoup = ["BeautifulSoup4"] +[[package]] +name = "packaging" +version = "26.0" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.8" +files = [ + {file = "packaging-26.0-py3-none-any.whl", hash = "sha256:b36f1fef9334a5588b4166f8bcd26a14e521f2b55e6b9de3aaa80d3ff7a37529"}, + {file = "packaging-26.0.tar.gz", hash = "sha256:00243ae351a257117b6a241061796684b084ed1c516a08c48a3f7e147a9d80b4"}, +] + [[package]] name = "pillow" version = "12.2.0" @@ -941,7 +975,21 @@ files = [ {file = "webencodings-0.5.1.tar.gz", hash = "sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923"}, ] +[[package]] +name = "whitenoise" +version = "6.12.0" +description = "Radically simplified static file serving for WSGI applications" +optional = false +python-versions = ">=3.10" +files = [ + {file = "whitenoise-6.12.0-py3-none-any.whl", hash = "sha256:fc5e8c572e33ebf24795b47b6a7da8da3c00cff2349f5b04c02f28d0cc5a3cc2"}, + {file = "whitenoise-6.12.0.tar.gz", hash = "sha256:f723ebb76a112e98816ff80fcea0a6c9b8ecde835f8ddda25df7a30a3c2db6ad"}, +] + +[package.extras] +brotli = ["brotli"] + [metadata] lock-version = "2.0" python-versions = ">=3.12,<3.13" -content-hash = "8284fc2ef5f2a06d27b41da40cc2067920b8fd5fed8f23621b777a15d8ca4559" +content-hash = "f0a03e4a068c519c6f13ec9816ea519c95ff650b1aa85915f17bc8ca364bf20a" diff --git a/pyproject.toml b/pyproject.toml index a6d5c85..521ee80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,8 @@ django-mptt = "^0.18.0" pytils = "^0.4.4" django-select2 = "^8.4.8" etpgrf = "^0.1.6" +gunicorn = "^25.3.0" +whitenoise = "^6.12.0" [tool.poetry.group.dev.dependencies] django-debug-toolbar = "^6.3"