title: How to use django cache with REST Framework?
body: <p>I'm fairly new to Django and try to get a working backend. So far, my backend is working fine, but I don't know, how to respond with custom data:</p>
  
  <p><strong>What I have:</strong></p>
  
  <ul>
  <li><p>Angular Frontend</p></li>
  <li><p>Django (REST) backend</p></li>
  <li>A working cache</li>
  </ul>
  
  <p><strong>What I want to achieve:</strong> </p>
  
  <p>I want to call an endpoint (lets say backend/weather). When I call this endpoint, I want to check my cache for a weather value. If there is one, I want to send it to the client. If there is none, I want to make an API call, store the retrieved value in my cache and send the value to the client. How can I do this. This is what I have so far:</p>
  
  <p><em>views.py</em></p>
  
  <pre><code>from rest_framework import viewsets
  
  from .models import Weather
  from .serializers import WeatherSerializer
  
  from django.core.cache import cache
  from urllib.request import urlopen
  import json
  
  
  class WeatherView(APIView):
  
      def get(self):
          if(cache.get('temp') == None):
              url = 'https://api.openweathermap.org/data/2.5/forecast?q=' + '...';
              serialized_data = urlopen(url).read()
              data = json.loads(serialized_data)
              print(data)
  
              cache.set('weatherdata', data, 3600)
          else:
              data = cache.get('weatherdata')
  
          serializer_class = WeatherSerializer(data)
  
          responseJSON = JSONRenderer().render(serializer_class.data)
  
          return Response(responseJSON)
  </code></pre>
  
  <p><em>serializers.py</em></p>
  
  <pre><code>from rest_framework import serializers
  from .models import Weather
  
  
  class WeatherSerializer(serializers.Serializer):
  
      temp = serializers.DecimalField(max_digits=4, decimal_places=2)
      iconName = serializers.CharField()
  </code></pre>
  
  <p><em>urls.py</em></p>
  
  <pre><code>from django.urls import path, include
  from . import views
  from rest_framework import routers
  from django.conf import settings
  from django.conf.urls.static import static
  
  router = routers.DefaultRouter()
  
  urlpatterns = [
      path('', include(router.urls)),
      path('weather', views.WeatherView)
  ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  
  </code></pre>
  
  <p>I get the data from the API. My cache setting and getting are also working. But I don't know how to respond with custom data. I'm getting the following error when calling backend/weather: </p>
  
  <pre><code>TypeError at /weather
  __init__() takes 1 positional argument but 2 were given
  Request Method: GET
  Request URL:    http://127.0.0.1:8000/weather
  Django Version: 2.2.7
  Exception Type: TypeError
  Exception Value:    
  __init__() takes 1 positional argument but 2 were given
  </code></pre>
  
  <p>Thank you in advance!</p>