feat: add favicon support with SVG response and update templates and tests
All checks were successful
Build and Push Docker Image / build (push) Successful in 26s

- Implemented a `favicon` view to serve a custom SVG favicon
- Added `favicon.ico` route to `urls.py`
- Updated `base.html` to include favicon link tag
- Suppressed specific Django ASGI warnings in DEBUG mode
- Added unit tests to verify favicon behavior and response
This commit is contained in:
2026-04-21 17:56:12 +02:00
parent c4eb40f265
commit dab33a03a1
5 changed files with 43 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
from django.core import mail
from django.test import TestCase, override_settings
from django.test import SimpleTestCase, TestCase, override_settings
from django.urls import reverse
@@ -36,3 +36,12 @@ class FaqQuestionTests(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(len(mail.outbox), 0)
self.assertContains(response, "Необходимо согласие на обработку персональных данных.")
class FaviconTests(SimpleTestCase):
def test_favicon_route_returns_icon(self):
response = self.client.get(reverse("favicon"))
self.assertEqual(response.status_code, 200)
self.assertEqual(response["Content-Type"], "image/svg+xml")
self.assertIn(b"<svg", response.content)

View File

@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/5.2/ref/settings/
"""
import os
import warnings
from pathlib import Path
from urllib.parse import urlparse
@@ -151,6 +152,17 @@ SECRET_KEY = os.getenv("SECRET_KEY", "django-insecure-*%u*i415=%@ny05mbd-j3802bc
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env_bool("DEBUG", True)
if DEBUG:
warnings.filterwarnings(
"ignore",
message=(
"StreamingHttpResponse must consume synchronous iterators in order to "
"serve them asynchronously. Use an asynchronous iterator instead."
),
category=Warning,
module=r"django\.core\.handlers\.asgi",
)
ALLOWED_HOSTS = merge_unique(
collect_hosts("COOLIFY_FQDN", "COOLIFY_URL", "ALLOWED_HOSTS"),
["127.0.0.1", "localhost", "preview-1.azimkin.dev"],

View File

@@ -17,10 +17,13 @@ Including another URLconf
from django.contrib import admin
from django.urls import path, include
from santehray import views
urlpatterns = [
path("favicon.ico", views.favicon, name="favicon"),
path('', include('home.urls')),
path('catalog/', include('items.urls')),
path('orders/', include('orders.urls')),
path('users/', include('users.urls')),
path('admin/', admin.site.urls),
]
]

16
santehray/views.py Normal file
View File

@@ -0,0 +1,16 @@
from django.http import HttpResponse
_FAVICON_SVG = """<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="SantehRay">
<rect width="64" height="64" rx="14" fill="#123b40"/>
<rect x="14" y="29" width="36" height="6" rx="3" fill="#f2b544"/>
<circle cx="18" cy="32" r="7" fill="#f5f1e8"/>
<circle cx="46" cy="32" r="7" fill="#f5f1e8"/>
<circle cx="18" cy="32" r="3" fill="#123b40"/>
<circle cx="46" cy="32" r="3" fill="#123b40"/>
</svg>
"""
def favicon(request):
return HttpResponse(_FAVICON_SVG, content_type="image/svg+xml")

View File

@@ -5,6 +5,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Santehray - {% block title %}{{ title }}{% endblock %}</title>
<link rel="icon" type="image/svg+xml" href="{% url 'favicon' %}">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap"