Представления
Представления, основанные на классах
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import authentication, permissions
from django.contrib.auth.models import User
class ListUsers(APIView):
"""
View to list all users in the system.
* Requires token authentication.
* Only admin users are able to access this view.
"""
authentication_classes = [authentication.TokenAuthentication]
permission_classes = [permissions.IsAdminUser]
def get(self, request, format=None):
"""
Return a list of all users.
"""
usernames = [user.username for user in User.objects.all()]
return Response(usernames)Атрибуты политики API
.renderer_classes
.parser_classes
.authentication_classes
.throttle_classes
.permission_classes
.content_negotiation_class
Методы инстанцирования политики API
.get_renderers(self)
.get_parsers(self)
.get_authenticators(self)
.get_throttles(self)
.get_permissions(self)
.get_content_negotiator(self)
.get_exception_handler(self)
Методы реализации политики API
.check_permissions(self, request)
.check_throttles(self, request)
.perform_content_negotiation(self, request, force=False)
Dispatch методы
.initial(self, request, *args, **kwargs)
.handle_exception(self, exc)
.initialize_request(self, request, *args, **kwargs)
.finalize_response(self, request, response, *args, **kwargs)
Представления на основе функций
@api_view()
Декораторы политики API
Декоратор схемы представления
Last updated
Was this helpful?