[Django]-How to use @condition decorator for REST view classes

2👍

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.

2👍

You can use django-rest-framework-condition

Install it:

pip install django-rest-framework-condition

Use it in the same way as decorator from Django:

from rest_framework_condition import condition

class MyView(GenericAPIView):
    serializer_class = MySerializer

    @condition(etag_func=get_language_etag)
    def get(self, request, *args, **kwargs):
        return Response(self.get_cached_response())
👤jozo

Leave a comment