Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kayode-adechinan/039241ddf1591f43e593287556c1e4b8 to your computer and use it in GitHub Desktop.
Save kayode-adechinan/039241ddf1591f43e593287556c1e4b8 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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment