Answers for "define and call a function in django API"

0

define and call a function in django API

# views.py
from rest_framework.views import APIView

def addTwoNumber(a,b):
    return a+b

class MyView(APIView):
    def post(self, request, *args, **kwargs):
        my_result=addTwoNumber(request.data.get('firstnum'),request.data.get('secondnum'))
        return Response(data={"my_return_data":my_result})

# urls.py
urlpatterns = [
    url(r'^myview/$', MyView.as_view()),
    ...
]
Posted by: Guest on September-27-2021

Code answers related to "define and call a function in django API"

Python Answers by Framework

Browse Popular Code Answers by Language