Friday, 6 May 2022

Django Views

 Handles HTTP request, 

specifies seralizer to serialize data,


views also contain 

renderer_class so it can render serailzer in Django provided UI to try out API.

    # Renderer (Can test this API on browser, traditional has to use CURL)

    renderer_classes = api_settings.DEFAULT_RENDERER_CLASSES

Serailizer can also initiate 

    password = serializers.CharField(

        style={'input_type': 'password'},

        trim_whitespace=False

    )


for styles in the HTTP API try out section 


serailzer can overwrite write types by views like (CreateAPIView)


if validators write own built in def create() etc.


can use authentication class, permission class to autheticate user

// Authentication checks token header

    serializer_class = UserSerializer

    # https://www.django-rest-framework.org/api-guide/authentication/

    # Validate header: token: XXXXX

    authentication_classes = (authentication.TokenAuthentication,)

    # Permission to use API

    # https://www.django-rest-framework.org/api-guide/permissions/

    permission_classes = (permissions.IsAuthenticated,)



returns objects by default in different view types like CreateAPIView, ObtainAuthTokenView


Those views accepts GET, PUT POST accordingly by default, I.E CreateAPIView does not support get,

they also return different mode objects by default :


https://www.django-rest-framework.org/tutorial/3-class-based-views/



No comments:

Post a Comment