define and call a function in django api

Solutions on MaxInterview for define and call a function in django api by the best coders in the world

showing results for - "define and call a function in django api"
Ana Paula
19 Aug 2020
1# views.py
2from rest_framework.views import APIView
3
4def addTwoNumber(a,b):
5    return a+b
6
7class MyView(APIView):
8    def post(self, request, *args, **kwargs):
9        my_result=addTwoNumber(request.data.get('firstnum'),request.data.get('secondnum'))
10        return Response(data={"my_return_data":my_result})
11
12# urls.py
13urlpatterns = [
14    url(r'^myview/$', MyView.as_view()),
15    ...
16]