A repost on Getting started with Flask from my erstwhile blog : codesandboards.wordpress.org
I am always fascinated by the power of the internet and the impact web applications creates making the internet as the most effective medium to share information in the present day context. The internet is now the ultimate warehouse of all possible kinds of data and is thus, a great platform to build better and more useful web applications. This post is based on my experience getting started with Flask and D3.js.
For starters,a small introduction to Flask and D3. Flask is a micro web framework, that is a light- weight and ideal for small web applications. Flask and Django the two popular web frameworks available in Python are widely used for developing a lot of web applications. Django is ideal for full-stack developers (I’ll write about Django in another post).D3 is the popular data visualization library is used to visualize the results of the processing we do. As far as installation goes, we install only Flask, D3.js is imported during run time in our web application. We install Flask with “pip” with the following command:
pip install flask
To make flask available for all users in Linux or Unix based applications use the command:
sudo pip install flask
My first step getting started with ask was building simple “Hello World” application, the code is available in the homepage of Flask. That’s all with the introduction to Flask.
This application I built to get started with Flask is to map the states which has “High-Poverty” projects in public schools across the US. This application is inspired from a tutorial in YouTube.
The code is very straight forward with the Flask application aka the Python script fetches the data from Donor Choose’s API as JSON objects and dumps it into a JSON string. We use urllib2, to open the link and json library to process the JSON objects.The JSON string is returned as a list of all the states with High Poverty projects.
The outputs is visualized using D3.js in a HTML le, which access the JSON list and plots it onto a SVG map of USA.
The code is available in Github.
While trying the code for yourself – navigate to the directory “getting-started-with- ask-
d3.js” and run the Python script “services.py”.
This script will create a server instance at a local IP address at http://127.0.0.1:5000/ .
This renders a web page with a message “Everything is running”.
Now, to visualize the results after processing the JSON objects, go to http://127.0.0.1:5000/projects/highpoverty/states .
If you look into the code you’ll notice that the path given in the hyperlink is same as the @app.route() parameter in the Python script. The page renders a result similar to this image.
Okay, I guess that’s all I have at the moment.
My next post will also revolve around Flask, where I’ll build my own real time Earthquake feed application on Flask. Stay tuned!
Please do visit the video tutorial , it was how I got started and I owe this work to them 🙂