O'Reilly logo

Instant Flask Web Development by Ron DuPlain

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Running a simple application (Simple)

Let's get started by running a simplest Flask application.

Getting ready

Make sure you have activated your virtualenv tool as described in the previous section.

How to do it...

  1. Put this code into a file named hello.py:
    from flask import Flask
    
    app = Flask(__name__)
    
    @app.route('/')
    def hello():
        return 'Hello, world!'
    
    if __name__ == '__main__':
        app.run()
  2. Run this application from the console:
    $ python hello.py
  3. If this runs correctly, you will see:

    * Running on http://127.0.0.1:5000/

    This is a URL, which you can visit in your browser. When you do, your browser will display a plain page which says "Hello, world!" (without quotes). Note that the address 127.0.0.1 refers to localhost, such that Flask will only respond to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required