helloWorld.py
We write the application code for our Hello world application in a file named helloWorld.py
:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
Running the application
The application can then be started by setting the enviornment variable FLASK_APP
to the name of the Python script we created and executing flask run
:
$ FLASK_APP=helloWorld.py flask run
* Serving Flask app 'helloWorld.py'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
The application is now visible on a browser by connnecting to http://localhost:5000
.
Note the warning!