Getting Started with Flask

Flask is a micro web framework written in Python, one of the most simple frameworks out there and easiest to start with.

To get started all u need to do is have python installed and type this.

  • terminal
pip install flask
touch app.py
  • app.py
from flask import Flask

app = Flask(__name__)


@app.route('/')
def index():
    return '<h1>Hello world </h1>'


if __name__ == "__main__":
    app.run()
  • terminal
flask run

So lets talk about what we did here

  • We installed flask with PIP, and created a file “app.py”.
  • Then in “app.py”,
    • We import Flask from flask and create a flask object
    • then using @app.route('/') we assign a route at ‘/’ to render the return statement i.e a simple html syntax of “Hello world”
    • Finally we used app.run() to start call our flask object and start the server
  • Finally using flask run we run our “app.py” (“app” is default FLASK_APP so no need to specify specific entry point ).

now if you click on the link or go to http://127.0.0.1:5000/ you will be greeted with

That’s all it takes to start a flask sever , obviously to master flask u will need spend countless hours and make a proper project, but then again

“Rome wasn’t built in a day”

Leave a comment

Design a site like this with WordPress.com
Get started