I am trying to use the ETAG HTTP header to send 304 NOT MODIFIED responses. The following code is used:
class MyView(GenericAPIView):
serializer_class = MySerializer
@condition(etag_func=get_language_etag)
def get(self, request, *args, **kwargs):
return Response(self.get_cached_response())
The problem lies in the 'self' parameter of the get method. This jumbles the parameters in the @condition generator method here the beginning of the condition method:
def condition(etag_func=None, last_modified_func=None):
def decorator(func):
@wraps(func, assigned=available_attrs(func))
def inner(request, *args, **kwargs):
as now 'self' gets assigned to request and the actual requests ends up in *args.
Has anyone had a similar problem concerning decorators and their expected order of parameters?
drf-extensions provides caching and ETag mixins that you can use on your views, instead of using the ones provided by Django.
https://chibisov.github.io/drf-extensions/docs/#cache-etag-mixins
It is not possible to use the methods provided by Django before DRF does not use the standard HttpResponse classes, and most of the decorators are expecting it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With