[Django]-Django return json and html depending on client python

7👍

Use different URLs for the JSON and HTML versions.

I suggest that your JSON version be available on a url like r'normal/api(?P<json_flag>/json/?)$', and have a parameter in your view to receive the json flag. You can then serve appropriately.

Naturally, your view will have to use different logic to generate HTML and JSON. I strongly suggest that you use the json module instead of a template to generate JSON.

👤Marcin

Leave a comment