THE RISE OF FLASK

Jack Arokiason J
featurepreneur
Published in
3 min readMay 2, 2021

About the article

  1. Flask Introduction
  2. requirements and setup
  3. Flask template
  4. Explanation

FLASK

Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions.

Flask is intended for web applications and is “micro” because it omits native tools and libraries for a “install what you need” approach

PYTHON

Python is one of the most preferred languages to build backend applications. Even when facing good old PHP and full-stack JavaScript, Python has its place because of the ease of implementation, and a supportive community that keeps beginners hooked.

Requirements and setup

  1. To Install python jump here
  2. Visual studio or PyCharm would be great (IDE)
  3. Installing flask using pip install flask

Flask Template

from flask import Flask           # import flask
app = Flask(__name__) # create an app instance

@app.route("/") # at the end point /
def hello(): # call method hello
return "Hello World!" # which returns "hello world"
if __name__ == "__main__": # on running python app.py
app.run(port=8003, debug=True) # run the flask app

To Start the Application

Run the application by running the `app.py` file. By default, the flask runs a local server at port 5000.

python app.py

Explanation

When we create our Flask object, we pass __name__ as a single argument. This sets the current file as the app’s anchor, letting Flask know how to import and build when necessary.

To create a route, we use our Flask object with the method .route() as a decorator. The single forward slash is the actual path we’re defining for the URL. If we had designate the route as ("/flask"), then we would need to enter localhost:5000/flask to access the subsequent function.

Speaking of, our function home() will be executed when the route is accessed. The function can be more robust, but the important takeaway here is that we return a value that is then printed to the screen.

Debug Mode

This is because we are running the server in a production model. For development purposes, we use something called as debug mode. When debug=Trueis set the server restarts as we add new code to our Flask Application. In order to set the debug mode do the following

  1. Modify the line app.run() to app.run(debug=True).
  2. Stop the running server and restart it again.

You will see “debugger is active” which means that the debug mode has taken effect. Now you can go on and edit your file as much as you want, and the server will be restarted.

Thank you!!!

--

--