Test:
{{{
class FaviconTests(SimpleTestCase):
def test_get(self):
response = self.client.get("/favicon.ico")
self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertEqual(response["Cache-Control"], "max-age=86400,
immutable, public")
self.assertEqual(response["Content-Type"], "image/png")
content = b"".join(response.streaming_content)
self.assertGreater(len(content), 0)
}}}
View:
{{{
from django.conf import settings
from django.http import FileResponse
from django.views.decorators.cache import cache_control
from django.views.generic.base import View
class FaviconView(View):
@cache_control(max_age=60 * 60 * 24, immutable=True, public=True)
def get(self, request, *args, **kwargs):
file = (
settings.BASE_DIR / settings.STATIC_ROOT / "img" / "favicon-
32x32.png"
).open("rb")
return FileResponse(file)
}}}
Error:
TypeError: cache_control didn't receive an HttpRequest. If you are
decorating a classmethod, be sure to use @method_decorator.
--
Ticket URL: <https://code.djangoproject.com/ticket/33798>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Matt Hegarty):
Hacking this fixes the test:
{{{
if not hasattr(request.request, "META"):
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33798#comment:1>
Comment (by Matt Hegarty):
I believe issue introduced here:
https://github.com/django/django/commit/40165eecc40f9e223702a41a0cb0958515bb1f82
--
Ticket URL: <https://code.djangoproject.com/ticket/33798#comment:2>
Comment (by Matt Hegarty):
OK, silly me. I should have paid more attention to the message. This
fixes it:
{{{
@method_decorator(cache_control(max_age=60 * 60 * 24, immutable=True,
public=True), name='dispatch')
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33798#comment:3>
* status: new => closed
* resolution: => invalid
--
Ticket URL: <https://code.djangoproject.com/ticket/33798#comment:4>