diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml
index 9cbfc64..58aa9d8 100644
--- a/docker-compose.prod.yml
+++ b/docker-compose.prod.yml
@@ -45,6 +45,12 @@ services:
cp /nginx_configs_host/nginx/oknardia-app--external-nginx.conf.example /nginx_configs_host/nginx/oknardia-app--external-nginx.conf;
echo 'INIT: Created new nginx config with correct paths';
fi &&
+ ERROR_DIR=/home/app/web/public/media/_error &&
+ mkdir -p "$$ERROR_DIR" &&
+ for code in 400 401 403 404 413 429 500 502 503 504; do
+ cp /home/user/path-to-oknardia-app/oknardia/templates/error/$${code}.html "$$ERROR_DIR/$${code}.html";
+ done &&
+ cp /home/user/path-to-oknardia-app/oknardia/templates/error/under_reconstruction.html "$$ERROR_DIR/under_reconstruction.html"
python -m gunicorn --workers 2 --bind 0.0.0.0:8000 --timeout 120 oknardia.wsgi:application"
# Пробрасывание портов
diff --git a/oknardia/oknardia/urls.py b/oknardia/oknardia/urls.py
index 7d2245d..2e6ae99 100644
--- a/oknardia/oknardia/urls.py
+++ b/oknardia/oknardia/urls.py
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
"""oknardia Конфигурация URL"""
from django.contrib import admin
-from django.urls import include, path, re_path
-from django.conf.urls.static import static
+from django.urls import include, re_path, path
from django.http import FileResponse
from pathlib import Path
import environ
import mimetypes
+import os
# Инициализируем env
env = environ.Env()
@@ -174,10 +174,13 @@ PUBLIC_ROOT_URLPATTERNS = [
# (чтобы отдавать файлы быстро и не проверять остальные рулы)
urlpatterns = [*PUBLIC_ROOT_URLPATTERNS, *urlpatterns]
+handler404 = 'web.views.handler404'
+handler400 = 'web.views.handler400'
+handler403 = 'web.views.handler403'
+handler500 = 'web.views.handler500'
# Для локального тестирования production конфига: отдача медиа через Django
# В реальном production медиа обслуживает Nginx!
-import os
if DEBUG or env.bool('ALLOW_MEDIA_SERVE', default=False):
from django.views.static import serve as serve_static
# Проверяем что директория медиа существует
@@ -196,6 +199,13 @@ if DEBUG or env.bool('ALLOW_MEDIA_SERVE', default=False):
if DEBUG:
# --- страничка для тестирования верстки текста в блоге
urlpatterns += [re_path(r'^blog/tmp[/*]$', service.tmp),]
+ # --- странички для тестирования страниц с кодами ошибок
+ urlpatterns += [
+ re_path(r'^400$', views.handler400),
+ re_path(r'^403$', views.handler403),
+ re_path(r'^404$', views.handler404),
+ re_path(r'^500$', views.handler500),
+ ]
# ___ ____ _ _____ _ _ _____ _
# | | | | \ ___| |_ _ _ ___ |_ _|___ ___| | |_ ___ ___ | _ |___ ___ ___| |
# |_ | | | | -_| . | | | . | | | | . | . | | . | .'| _| | __| .'| | -_| |
diff --git a/oknardia/templates/error/400.html b/oknardia/templates/error/400.html
new file mode 100644
index 0000000..7d282b9
--- /dev/null
+++ b/oknardia/templates/error/400.html
@@ -0,0 +1,31 @@
+
+
+
+
+ 400 — Некорректный запрос
+
+
+
+
+
+
+
+
diff --git a/oknardia/templates/error/401.html b/oknardia/templates/error/401.html
new file mode 100644
index 0000000..d0b71b0
--- /dev/null
+++ b/oknardia/templates/error/401.html
@@ -0,0 +1,29 @@
+
+
+
+
+ 401 — Требуется авторизация
+
+
+
+
+
+
+
diff --git a/oknardia/templates/error/403.html b/oknardia/templates/error/403.html
new file mode 100644
index 0000000..48235c5
--- /dev/null
+++ b/oknardia/templates/error/403.html
@@ -0,0 +1,32 @@
+
+
+
+
+ 403 — Доступ запрещён
+
+
+
+
+
+
+
403
+
Доступ запрещён
+
У вас нет прав для доступа к этому ресурсу. Если вы считаете это ошибкой, свяжитесь с администратором.
+
Вернуться на главную oknardia.ru
+
+
+
+
+
diff --git a/oknardia/templates/error/404.html b/oknardia/templates/error/404.html
new file mode 100644
index 0000000..fd01ed2
--- /dev/null
+++ b/oknardia/templates/error/404.html
@@ -0,0 +1,31 @@
+
+
+
+
+ 404 — Страница не найдена
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/oknardia/templates/error/413.html b/oknardia/templates/error/413.html
new file mode 100644
index 0000000..5d65fad
--- /dev/null
+++ b/oknardia/templates/error/413.html
@@ -0,0 +1,29 @@
+
+
+
+
+ 413 — Файл слишком большой
+
+
+
+
+
+
+
diff --git a/oknardia/templates/error/429.html b/oknardia/templates/error/429.html
new file mode 100644
index 0000000..8fe363b
--- /dev/null
+++ b/oknardia/templates/error/429.html
@@ -0,0 +1,29 @@
+
+
+
+
+ 429 — Слишком много запросов
+
+
+
+
+
+
+
diff --git a/oknardia/templates/error/500.html b/oknardia/templates/error/500.html
new file mode 100644
index 0000000..e6ab239
--- /dev/null
+++ b/oknardia/templates/error/500.html
@@ -0,0 +1,31 @@
+
+
+
+
+ 500 — Внутренняя ошибка сервера
+
+
+
+
+
+
+
500
+
Внутренняя ошибка сервера
+
На нашем сервере произошла непредвиденная ошибка. Команда разработчиков уже работает над решением проблемы.
+
Если проблема сохраняется, пожалуйста, свяжитесь с администратором: info@oknardia.ru
+
+
+
+
diff --git a/oknardia/templates/error/502.html b/oknardia/templates/error/502.html
new file mode 100644
index 0000000..89eb4f1
--- /dev/null
+++ b/oknardia/templates/error/502.html
@@ -0,0 +1,29 @@
+
+
+
+
+ 502 — Плохой шлюз
+
+
+
+
+
502
+
Плохой шлюз
+
Сервер приложения временно недоступен. Мы работаем над восстановлением работоспособности.
+
Пожалуйста, попробуйте перезагрузить страницу через несколько минут. Если проблема сохраняется, свяжитесь с нами: info@oknardia.ru
+
+
+
+
diff --git a/oknardia/templates/error/503.html b/oknardia/templates/error/503.html
new file mode 100644
index 0000000..680ee1c
--- /dev/null
+++ b/oknardia/templates/error/503.html
@@ -0,0 +1,29 @@
+
+
+
+
+ 503 — Сервис недоступен
+
+
+
+
+
503
+
Сервис недоступен
+
Сайт временно недоступен для плановых работ. Мы скоро вернёмся!
+
Информация об обслуживании обновляется автоматически. Спасибо за терпение!
+
+
+
+
diff --git a/oknardia/templates/error/504.html b/oknardia/templates/error/504.html
new file mode 100644
index 0000000..53a34c1
--- /dev/null
+++ b/oknardia/templates/error/504.html
@@ -0,0 +1,29 @@
+
+
+
+
+ 504 — Тайм-аут шлюза
+
+
+
+
+
504
+
Тайм-аут шлюза
+
Сервер приложения слишком долго отвечает на запрос. Это может быть перегрузка или технический сбой.
+
Попробуйте перезагрузить страницу через несколько минут. Если проблема повторится, свяжитесь с поддержкой: info@oknardia.ru
+
+
+
+
diff --git a/oknardia/templates/error/under_reconstruction.html b/oknardia/templates/error/under_reconstruction.html
new file mode 100644
index 0000000..fb0991a
--- /dev/null
+++ b/oknardia/templates/error/under_reconstruction.html
@@ -0,0 +1,29 @@
+
+
+
+
+ Технические работы
+
+
+
+
+
+
+
diff --git a/oknardia/web/views.py b/oknardia/web/views.py
index 62e9a69..f4f9449 100644
--- a/oknardia/web/views.py
+++ b/oknardia/web/views.py
@@ -242,3 +242,66 @@ def get_address(request: HttpRequest) -> HttpResponse:
'ticks': float(time.perf_counter() - time_start),
})
return render(request, "popup/popup_show_apartment_variants.html", to_template)
+
+
+# ============================================================================
+# ОБРАБОТЧИКИ ОШИБОК ДЛЯ ТЕСТИРОВАНИЯ В DEBUG РЕЖИМЕ
+# ============================================================================
+# Используется в urls.py при DEBUG=True для тестирования верстки страниц ошибок.
+# Позволяет визуально проверить, как выглядят страницы 400, 403, 404 и 500
+# без необходимости искусственно вызывать реальные ошибки.
+
+
+def handler400(request: HttpRequest, exception=None) -> HttpResponse:
+ """Отображает страницу ошибки 400 (Bad Request).
+
+ Используется только в DEBUG режиме для тестирования верстки.
+
+ :param request: входящий http-запрос
+ :param exception: исключение (если есть)
+ :return response: исходящий http-ответ с кодом 400
+ """
+ response = render(request, "error/400.html", {})
+ response.status_code = 400
+ return response
+
+
+def handler403(request: HttpRequest, exception=None) -> HttpResponse:
+ """Отображает страницу ошибки 403 (Forbidden).
+
+ Используется только в DEBUG режиме для тестирования верстки.
+
+ :param request: входящий http-запрос
+ :param exception: исключение (если есть)
+ :return response: исходящий http-ответ с кодом 403
+ """
+ response = render(request, "error/403.html", {})
+ response.status_code = 403
+ return response
+
+
+def handler404(request: HttpRequest, exception=None) -> HttpResponse:
+ """Отображает страницу ошибки 404 (Not Found).
+
+ Используется только в DEBUG режиме для тестирования верстки.
+
+ :param request: входящий http-запрос
+ :param exception: исключение (если есть)
+ :return response: исходящий http-ответ с кодом 404
+ """
+ response = render(request, "error/404.html", {})
+ response.status_code = 404
+ return response
+
+
+def handler500(request: HttpRequest) -> HttpResponse:
+ """Отображает страницу ошибки 500 (Internal Server Error).
+
+ Используется только в DEBUG режиме для тестирования верстки.
+
+ :param request: входящий http-запрос
+ :return response: исходящий http-ответ с кодом 500
+ """
+ response = render(request, "error/500.html", {})
+ response.status_code = 500
+ return response