Using API to get data and display it on my website using DJANGO..

1,023 views
Skip to first unread message

Rij K

unread,
Jan 20, 2016, 8:13:59 PM1/20/16
to Django users
Hi all,

I'm trying to implement data and graphs from "http://data.london.gov.uk/" into my website by using an API (http://data.london.gov.uk/developers/) provided by them but I'm not too sure where to get started?

Would anyone be up for giving me a hand with this?

Many thanks.

Muhammad M

unread,
Jan 20, 2016, 8:32:01 PM1/20/16
to django...@googlegroups.com
Hi Rij,

I would approach it like this (though there might be alternative routes to the same results):

First: Where is the data?

According to your links, the various API endpoints are in the “results” list of the JSON on  http://data.london.gov.uk/api/3/action/package_list 

To get access data from a particular dataset/endpoint, you can “generate” thus:

1. Go to http://data.london.gov.uk/api/3/action/package_list and grab a dataset endpoint that interests you. I will choose the first one that comes up: 19-year-olds-qualified-to-nvq-level-3

2. “Generate” the API endpoint for this dataset by appending its URL to http://data.london.gov.uk/api/3/action/package_show?id=    (as per the documentation).


3. Fetch the data from the API 
There are many tools out there, but my favorite is Python-Requests. See the docs at http://docs.python-requests.org/en/latest/ 

Now, in your Python program/Django models or views modules, do:

import requests


response = requests.get(url)

4. Use the data as you see fit. The “response” object you (successfully) get from the line above contains all the data you need from the dataset you chose. See the Python-Requests docs
for all the ways to extract that data. And, then pass that data onto whatever other program, package or module you want to use to analyze or graph the response data. Also see the data portal for all the ways you can interact with their API.

I hope this helps. All the best.

Sincerely,
Muhammad 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4ba0df59-5323-4400-8f81-f71e839bd0ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rij K

unread,
Jan 21, 2016, 2:53:41 PM1/21/16
to Django users
Thank you Muhammad for your constructive guide, really appreciate the help provided! :)

Kind regards,

RJ
Reply all
Reply to author
Forward
0 new messages