init commit
This commit is contained in:
28
exercise/views.py
Normal file
28
exercise/views.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from django.shortcuts import render
|
||||
from .models import *
|
||||
from .serializers import *
|
||||
|
||||
from django.shortcuts import render
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth import authenticate
|
||||
from rest_framework.authentication import TokenAuthentication
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.decorators import authentication_classes
|
||||
from rest_framework.decorators import permission_classes
|
||||
from django.core.cache import cache
|
||||
|
||||
# Create your views here.
|
||||
@api_view(['GET'])
|
||||
def all_exercises(request):
|
||||
if 'all_exercises' in cache:
|
||||
data = cache.get('all_exercises')
|
||||
return Response(data=data, status=status.HTTP_200_OK)
|
||||
|
||||
users = Exercise.objects.all()
|
||||
serializer = ExerciseSerializer(users, many=True)
|
||||
data = serializer.data
|
||||
cache.set('all_exercises', data, timeout=None)
|
||||
return Response(data=data, status=status.HTTP_200_OK)
|
||||
Reference in New Issue
Block a user