PYTHON FLASK TUTORIAL

Hemalatha M

Introduction to Flask

Flask is a lightweight Python web framework used to build web applications. It was created by Armin Ronacher, who leads an international group of Python enthusiasts called POCCO. Flask provides useful libraries and tools but keeps things simple, which is why it’s known as a micro-framework.

What is Flask?

Flask is based on two main components:
  • WSGI (Web Server Gateway Interface) – a standard that defines how a Python web application communicates with a web server.
  • Jinja2 Template Engine – used to create dynamic web pages by combining templates with data.

What is WSGI?

WSGI stands for Web Server Gateway Interface. It acts as a bridge between the web server and your Python web application, making it easier to run Python apps on different servers.

What is Jinja2?

Jinja2 is a template engine that allows you to generate dynamic HTML pages. It takes data from your application and merges it with templates to create web pages for users.

Flask Environment Setup

Before installing Flask, make sure you have Python 2.7 or higher installed. It’s recommended to use Python 3 for development.

Install Virtual Environment

It’s a good practice to use a virtual environment while working with Flask. A virtual environment keeps your project’s dependencies separate from the system Python.

Step 1: Install virtualenv using:
  • $ pip install virtualenv
Create a new folder and set up your environment:
  • $ mkdir new  
  • $ cd new  
  • $ virtualenv venv
Step 2: Activate Virtual Environment:

On Linux/macOS:
  • $ venv/bin/activate
On Windows:
  • $ venv\scripts\activate

Step 3: Install Flask:

After activating the environment, install Flask using

  • $ pip install flask
(You can also install Flask directly without creating a virtual environment, but using one is recommended).

Step 4: Testing Flask Installation:

To check if Flask was installed correctly, open the terminal and run
  • python
This will open the Python shell. Inside the shell, type:
  • import flask

If you don’t see an error, Flask has been installed successfully.



Our website uses cookies to enhance your experience. Learn More
Accept !