1. 程式人生 > >Django REST Framework extensions

Django REST Framework extensions

pre sets time install response hub pps ros href

GitHub:https://github.com/chibisov/drf-extensions

官方文檔:http://chibisov.github.io/drf-extensions/docs/

安裝

pip install drf-extensions

cache用法

1、使用

from myapps.serializers import UserSerializer
from rest_framework_extensions.cache.mixins import CacheResponseMixin

class UserViewSet(CacheResponseMixin, viewsets.ModelViewSet):
    serializer_class = UserSerializer

2、設置過期時間,配置在settings.py

REST_FRAMEWORK_EXTENSIONS = {
    ‘DEFAULT_CACHE_RESPONSE_TIMEOUT‘: 5
}

Django REST Framework extensions