A friend called me the other day wanting to learn more about putting together a Flask application. After brewing a good Catimor coffee variety from Dominican Republic I decided to get a sample Flask code for starters and share it with everybody.
This Flask application includes:
- Importing the Flask class from the
flaskmodule. - Creating a Flask application instance with
app = Flask(__name__). - Defining a route
/using the@app.route()decorator and a corresponding view function (index()) that returns a simple message. - Running the Flask application with
app.run().
You can save this code to a Python file (e.g., app.py) and run it using Python. The Flask development server will start, and you can access the application in your web browser at http://localhost:5000/.
from flask import Flask
# Create a Flask application instance
app = Flask(__name__)
# Define a route and its corresponding view function
@app.route('/')
def index():
return 'Hello, World!'
# Run the Flask application
if __name__ == '__main__':
app.run(debug=True)
As usual, you can contact me if you have any questions or want to collaborate.

