Introduction And Installing Flask

Jan. 31, 2023, 8:55 p.m.

python flask

Flask is a micro web framework written in Python. It is easy to learn and ideal for small to medium sized web applications. To create a blog using Flask, you will first need to install it.

I Assume you have :

Basic knowledge of Python programming language.

Check if Python is installed in your system

Open terminal and run below command
python --version

Creating environment

It is recommended to use virtual environment for dependencies and other packages. 

Create a virtual environment

python -m venv env

Activate virtual environment

source env/bin/activate

Installing Flask

pip install Flask
This command install latest version of django in your system

Verify Installation

flask --version

Once you have Flask installed, you can start building your app by creating a new Flask application and setting up the required routes and templates. Here are the steps to create a basic Flask app:

  1. Create a new directory for your Flask project and navigate into it.
  2. Create a file called app.py and import Flask.
  3. Create an instance of the Flask class and define a route for the home page.
  4. Create templates for the home page and layout.
  5. Run the application and view it in your web browser.
from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def home():
    return render_template('home.html')

if __name__ == '__main__':
    app.run(debug=True)

You can then create templates for the home page and layout, and run the application to view it in your web browser. This is just a basic example, and you can build upon it to add more features and functionality to your app.

author image

bracketcoders

A learing portal for your coding interest.

View Profile