mirror of
https://github.com/jointakahe/takahe.git
synced 2024-12-23 22:10:28 +00:00
Set the correct Content-Type
header for static WebP images (#171)
This commit is contained in:
parent
2131b40ce0
commit
61fbda0ebf
2 changed files with 13 additions and 2 deletions
|
@ -4,6 +4,7 @@ from django.templatetags.static import static
|
|||
from django.utils.decorators import method_decorator
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.views.generic import TemplateView, View
|
||||
from django.views.static import serve
|
||||
|
||||
from activities.views.timelines import Home
|
||||
from core.decorators import cache_page
|
||||
|
@ -89,3 +90,14 @@ class FlatPage(TemplateView):
|
|||
"title": self.title,
|
||||
"content": mark_safe(html),
|
||||
}
|
||||
|
||||
|
||||
def custom_static_serve(*args, **keywords):
|
||||
"""
|
||||
Set the correct `Content-Type` header for static WebP images
|
||||
since Django cannot guess the MIME type of WebP images.
|
||||
"""
|
||||
response = serve(*args, **keywords)
|
||||
if keywords["path"].endswith(".webp"):
|
||||
response.headers["Content-Type"] = "image/webp"
|
||||
return response
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from django.conf import settings as djsettings
|
||||
from django.contrib import admin as djadmin
|
||||
from django.urls import path, re_path
|
||||
from django.views.static import serve
|
||||
|
||||
from activities.views import compose, explore, follows, posts, search, timelines
|
||||
from api.views import api_router, oauth
|
||||
|
@ -219,7 +218,7 @@ urlpatterns = [
|
|||
# Media files
|
||||
re_path(
|
||||
r"^media/(?P<path>.*)$",
|
||||
serve,
|
||||
core.custom_static_serve,
|
||||
kwargs={"document_root": djsettings.MEDIA_ROOT},
|
||||
),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue