hello worlds

Installing Flask

Install flask with the following command:

  sudo pip install Flask

The pip utility may not be installed on your system by default. If you're on a Mac execute:

  sudo easy_install pip

And if you're on an Ubuntu machine:

  sudo apt-get install python-pip

There are other ways to install Flask, for instance on Ubuntu simply open a terminal and enter:

  sudo apt-get install python-flask

For more information see the Flask documentation.


Now create the file server.py and add the following:

# Flask server, woo!

from flask import Flask, request, redirect, url_for, send_from_directory

# Setup Flask app.
app = Flask(__name__)
app.debug = True

# Routes
def root():
  return app.send_static_file('index.html')

def static_proxy(path):
  # send_static_file will guess the correct MIME type
  return app.send_static_file(path)

if __name__ == '__main__':

You can run the server.py file by using the python command, or make the file executable and use the more fun ./ method:

  chmod 755 server.py

If all goes well with the server you should see output similar to:

   * Running on
 * Restarting with reloader

You can how enter http://localhost:5000 in your browser and access your new server.


If you go to the new server site at this point you should receive a HTTP 404 "File not found." error. This is because in the server we configured the default "/" route to serve index.html which we haven't created yet.

Create a static/index.html file and add the following for testing purposes:

  <!DOCTYPE html>
    <h1>Hello, Worlds...</h1>

Then return to your browser http://localhost:5000 and refresh the page.

You should see a nice welcoming "Hello, Worlds..." message.