I want to cache my API responses. I am using Django Rest Framework and want use for this purpose @cache_response() decorator from drf extensions.
I am following examples from: http://chibisov.github.io/drf-extensions/docs/#cache-response There are only examples of class based views.
When I apply it like this:
@api_view(http_method_names=['GET'])
@cache_response()
def my_view(request, some_arg):
(...)
I end up with error:
inner() takes at least 2 arguments (1 given)
Full traceback:
Traceback:
File "/Users/andi/.virtualenvs/adfoo/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
112. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/andi/.virtualenvs/adfoo/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
57. return view_func(*args, **kwargs)
File "/Users/andi/.virtualenvs/adfoo/lib/python2.7/site-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/Users/andi/.virtualenvs/adfoo/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
407. response = self.handle_exception(exc)
File "/Users/andi/.virtualenvs/adfoo/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
404. response = handler(request, *args, **kwargs)
File "/Users/andi/.virtualenvs/adfoo/lib/python2.7/site-packages/rest_framework/decorators.py" in handler
51. return func(*args, **kwargs)
Exception Type: TypeError at /api/foo/1/exhibitors/
Exception Value: inner() takes at least 2 arguments (1 given)
How should I apply it correctly?
DRF extensions specifies for the decorator following requirenets for decorated method:
1) It should be method of class which is inherited from rest_framework.views.APIView
2) It should return rest_framework.response.Response instance.
taking into account point 1) I am not sure if its at all possible..
here is the source of drf @api_view decorator https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/decorators.py
and here is the source of drf extension @cache_response decorator https://github.com/chibisov/drf-extensions/blob/master/rest_framework_extensions/cache/decorators.py
cache_responsedecorator, indeed urls are not the issue. - aumo