Consider the following Django REST view:
class TestList(APIView):
renderer_classes = [TemplateHTMLRenderer, JSONRenderer]
template_name = 'android/test.html'
def get(self, request):
queryset = Test.objects.all()
return Response({'test_qs': queryset})
The URLConf:
...
url(r'^test/$', test_views.TestList.as_view(), name = 'test'),
...
I designed the view implying that it would serve both regular webpages and API responses. The page is perfectly ok if I call it from browser, I see the expected template android/test.html
.
Now the problem arises when I try to call the url from cURL specifying json content-type in Accept header. I tried two options.
curl --header "application/json" http://127.0.0.1:8000
which still returns me the webpage template HTML code in place of JSON seemingly ignoring the --header
parameter
and
curl -i -H "Accept: application/json" http:127.0.0.1:8000/test/
which results in a long-stated error. Because I can't copy-paste it from cmd, I'll just attach the screenshot here.
Any ideas? Is the error lies in cURL request or my API itself ?