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()),
...
]