Flask Framework

What is a Framework?

The framework is the basis upon which software programs are built. It serves as a foundation for software developers, allowing them to create a variety of applications for certain platforms. It is a set of functions and predefined classes used to connect with the system software and handle inputs and outputs.

It simplifies the life of a developer while giving them the ability to use certain extensions and makes the online applications scalable and maintainable.

Frontend Development vs Backend Development

  1. The front end of a website is the area with which the user immediately interacts. It contains everything that users see and interact with: text colours and styles, images and videos, graphs and tables, the navigation menu, buttons, and colours. HTML, CSS, and JavaScript are used in developing the front end. Some of the frameworks for frontend are:
  • AngularJS
  • Sencha Ext JS
  • React
  1. The backend of a website refers to the server-side of the website. It saves and organizes data and ensures that everything on the client-side of the website functions properly. It is the section of the website that you are unable to interact with or access. It is the part of the software that has no direct communication with the users. Back End development is done using Java, Python, C#, and JavaScript. Some of the framework for the backend are :
    • Flask
    • Tornado
    • PyramidArmin Ronacher
    • Django

Flask Framework

Flask is used for developing web applications using python, implemented on Werkzeug and Jinja2. Advantages of using Flask framework are:

  • There is a built-in development server and a fast debugger provided.

  • Lightweight

  • Secure cookies are supported.

  • Templating using Jinja2.

  • Request dispatching using REST.

  • Support for unit testing is built-in.

Installation of Flask

Python Version

Install the latest version of Python or at least use a version >= Python 3.7

Creating Virtual Environment

Virtual environments are separate collections of Python libraries, one for each project. Installed packages for one project do not affect other projects or the operating system’s packages. Python has the venv package, which allows you to build virtual environments.

For Windows

mkdir myproject > cd myproject > py -3 -m venv venv

For Mac

$ mkdir myproject $ cd myproject $ python3 -m venv venv

Make the Environment Active

Before you begin working on your project, turn on the environment:

For Windows

venvScriptsactivate

For Mac

$ . venv/bin/activate

The name of the current active environment will be shown in your shell prompt.

Install Flask

Run the following command in the active environment to install Flask:

$ pip install Flask

HTTP methods

  • GET
  • POST

Currently, we will look at GET and POST, these are the most commonly used methods.

GET Method

GET is used to fetch information from a certain website.

POST Method

POST is used to send data to a server to update or create a resource.

2 Likes