I have a command line Python API for a Django app. When I access the app through the API it should return JSON and with a browser it should return HTML. I can use different URLs to access the different versions but how do I render the HTML template and JSON in the views.py with just one template?
To render the HTML I would use:
But how would I do the same for JSON without putting a JSON template? (the content-type should be application/json instead of text/html)
What would determine the JSON and HTML outputs?
So in my views.py: