Running a simple application (Simple)
Let's get started by running a simplest Flask application.
Make sure you have activated your virtualenv tool as described in the previous section.
How to do it...
- Put this code into a file named
from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return 'Hello, world!' if __name__ == '__main__': app.run()
- Run this application from the console:
$ python hello.py
- 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.1refers to localhost, such that Flask will only respond to ...