Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django rest framework function based views

from rest_framework.decorators import api_view, permission_classes, renderer_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response

@api_view(['GET'])
@permission_classes([IsAuthenticated])  # policy decorator
@renderer_classes([JSONRenderer])       # policy decorator
def items_not_done(request):
    user_count = Item.objects.filter(done=False).count()
    content = {'not_done': user_count}

    return Response(content)
Comment

django rest framework viewset

class UserViewSet(viewsets.ModelViewSet):
    """
    A viewset for viewing and editing user instances.
    """
    serializer_class = UserSerializer
    queryset = User.objects.all()
Comment

PREVIOUS NEXT
Code Example
Python :: How to Get the Union of Sets in Python 
Python :: raw input example python 
Python :: python bisect 
Python :: python select last item in list 
Python :: how to login using email in django 
Python :: how to make software in python 
Python :: python map() 
Python :: gridsearch cv 
Python :: modern tkinter 
Python :: mount gdrive in pyton 
Python :: find max number in list python 
Python :: python list deep copy 
Python :: how to update data in csv file using python 
Python :: name, *line = input().split() 
Python :: how to append number in tuple 
Python :: python split 
Python :: Python list files only in given directory 
Python :: python tkinter messagebox 
Python :: django forms error customize 
Python :: scaling pkl file? 
Python :: python temporary file 
Python :: username python system 
Python :: sns histplot nan values 
Python :: how to set pandas dataframe as global 
Python :: load png to python 
Python :: python 3 tkinter treeview example 
Python :: Add label to histogram 
Python :: using Decorators 
Python :: python __lt__ magic method 
Python :: seaborn boxplot legend color 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =