I have basic rest framework setup:
url(r'^items/$', ItemList.as_view(), name='item-list'),
...
class ItemList(generics.ListCreateAPIView):
model = Item
serializer_class = ItemSerializer
I want to cache this request using @cache_page
decorator. I tried something stupid like:
url(r'^items/$', cached_items, name='item-list'),
...
@cache_page(1000)
def cached_items(request):
return ItemList.as_view()
which doesn't work. How can I wrap those views properly?
With the same decorator you can use in the url patterns with class view as simple view (using .as_view
method)
from django.views.decorators.cache import cache_page
urlpatterns = ('',
url(r'^items/$', cache_page(60 * 60)(ItemList.as_view()), name='item-list')
)
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