Flask Creating First Simple Application (original) (raw)

Last Updated : 7 Jan, 2026

In this article, we will learn how to build a basic web application using Flask, which is a lightweight Python framework create and run web apps.

Prerequisites

To follow this article, you need:

Step-by-Step Process

**Step 1: Install Flask

To install Flask, open your terminal or command prompt and enter below command:

pip install Flask

This command installs Flask along with the required supporting libraries.

**Step 2: Create Your First Flask Application

Create a new Python file named app.py. This file will contain the code for your first Flask web application.

Python `

from flask import Flask

app = Flask(name)

@app.route('/') def hello_world(): return 'Hello World'

if name == 'main': app.run()

`

**Explanation:

**Step 3: Run the Flask Application

Run the command and you will see following in your terminal:

runningFlaskApp

Run the Flask Application

Open the given URL in your web browser to view your first Flask web page showing Hello World.

Output

Output of the above FlaskAPI app

**Step 4: Handling a POST Request Using an HTML Form

To understand how POST requests work in Flask, we will create a form that sends a user’s name to the server and displays it after submission.

**Folder Structure

Before writing any code, organize your project folder as shown below:

FolderStructure

App Folder Structure

**Explanation:

**Create the HTML Form

Inside the templates folder, create a file named name.html and add the following code:

HTML `

Enter Your Name



`

**Explanation:

Now, Update app.py as shown below:

Python `

from flask import Flask, request, render_template

app = Flask(name)

@app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': name = request.form['username'] return f"Hello {name}, POST request received" return render_template('name.html')

if name == 'main': app.run(debug=True)

`

**Output

Open the browser and visit http://127.0.0.1:5000/login

Running

Flask development server running successfully.

Now, Enter a name and click Submit

name

Entering a name in the form before submission.

The browser displays:

after_entering_name

Output displayed after submitting the form using POST request.

**Explanation: