api view wrapper django 1

api view wrapper django

from rest_framework.decorators import api_view

@api_view()
def hello_world(request):
    return Response({"message": "Hello, world!"})

Here is what the above code is Doing:
1. We’re importing the Response class from the rest_framework package.
2. We’re importing the api_view decorator from the rest_framework.decorators package.
3. We’re defining a function called hello_world, which takes a request object as an argument.
4. We’re returning a Response object that contains a dictionary with a “message” key.
5. We’re decorating the hello_world function with the api_view decorator.

Similar Posts