I'm using Django Rest Framework to create a non-model API endpoint, but I'm a having a bit of trouble setting it up. Below is my code.
views.py
from rest_framework import views, viewsets
from rest_framework.response import Response
from myproject.apps.policies.models import Customer
from .serializers import CustomerSerializer
class CustomerViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Customer.objects.all()
serializer_class = CustomerSerializer
class CalculateQuoteView(views.APIView):
def get(self, request, *args, **kwargs):
print('Just a random test.')
return Response({"success": True, "content": "Hello World!"})
My url.py file:
from django.conf.urls import include, url
from .policies import views as policies_views
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
router.register('policies', policies_views.CustomerViewSet)
#urlpatterns = router.urls
urlpatterns = [
url(r'^quote/', policies_views.CalculateQuoteView.as_view()),
url(r'^', include(router.urls)),
]
Using curl for testing:
curl -X GET http://localhost:8000/api/v1/policies/quote/ -H 'Authorization: Token 8636c43eb7a90randomtokenhere5c76555e93d3'
I get the following output:
{"detail":"Not found."}
Basically, in the end I will need to pass in details to the quote API endpoint and get some response data. Is there something I'm missing?
print('Just a random test.')executes while requesting?Not Found: /api/v1/policies/quote/.