Skip to content

Instantly share code, notes, and snippets.

@leemac
Created December 28, 2014 21:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save leemac/bf0cef7ad214cfc950dd to your computer and use it in GitHub Desktop.
Save leemac/bf0cef7ad214cfc950dd to your computer and use it in GitHub Desktop.
Example of returning a Django QuerySet as a JSON response (Django 1.7)
# Get the objects from the database
rawData = Launch.objects.all()
# Create array
json_res = []
# Iterate over results and add to array
for record in rawData:
json_obj = dict(name = record.name)
json_res.append(json_obj)
# Return the results
return HttpResponse(json.dumps(json_res), content_type='application/json')
@milidubey
Copy link

Thanks a tonne!

@diefun
Copy link

diefun commented Mar 25, 2021

Excellent approach! Thank a lot!

@cemusavi
Copy link

how to download it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment