Saturday, March 28, 2026

Basic Understanding of Flask (For Beginners)

 


1. What is Flask?

Flask is a Python web framework used to build websites and web applications.

👉 In simple terms:
Flask = a tool that helps you create websites using Python

2. Why Use Flask?

Flask is:

  • Simple and beginner-friendly
  • Lightweight (not complex)
  • Flexible (you can build anything from small to big apps)
  • Great for learning backend development

3. What is a Web Framework?

A web framework is a tool that:

  • Helps you handle web requests
  • Connects your code to the browser
  • Makes building websites easier

👉 Without Flask, building a web app from scratch is difficult.

4. How Flask Works


👉 Flow:

  1. User opens a website in browser
  2. Browser sends request to server
  3. Flask processes the request
  4. Flask returns a response (HTML page)
  5. Browser displays it

5. Installing Flask

Step 1: Install Python

Download from: python.org

Step 2: Install Flask

Open terminal and run:

pip install flask

6. Your First Flask App

from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
return "Hello, Flask!"

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

👉 Run this and open:
http://127.0.0.1:5000

7. Understanding the Code

  • Flask(__name__) → Creates the app
  • @app.route('/') → Defines the homepage
  • def home() → Function for the page
  • return → What is shown in browser

8. Routing (Creating Pages)

@app.route('/about')
def about():
return "This is the about page"

👉 Visit:

  • / → Home
  • /about → About page

9. Using HTML with Flask (Templates)

Flask uses HTML files to display pages.

Folder structure:

project/

├── app.py
└── templates/
└── index.html

HTML (templates/index.html):

<h1>Welcome to my website</h1>

Python:

from flask import render_template

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

10. Passing Data to HTML

@app.route('/user/<name>')
def user(name):
return f"Hello {name}"

👉 Visit:
/user/Daniel → Output: Hello Daniel

11. Forms in Flask (User Input)

from flask import request

@app.route('/submit', methods=['POST'])
def submit():
name = request.form['name']
return f"Hello {name}"

12. Flask vs Django (Simple Comparison)

FeatureFlaskDjango
ComplexitySimpleMore complex
FlexibilityHighStructured
Best forBeginners, small appsLarge applications

13. Real-Life Uses of Flask

Students can use Flask to:

  • Build personal websites
  • Create login systems
  • Develop dashboards
  • Build APIs
  • Create simple web apps
  • Connect Python to websites

14. Simple Project Idea (For Students)

👉 Build:

  • Personal portfolio website
  • Simple blog
  • Student registration system
  • Contact form website

15. Flask in Web Development

👉 Full stack view:

  • HTML → Structure
  • CSS → Design
  • JavaScript → Interactivity
  • Flask (Python) → Backend logic

16. Simple Summary

👉 Flask helps you:

  • Use Python for web development
  • Build dynamic websites
  • Handle user requests and data

Power Teaching Line (for your class)

👉 “Flask is the bridge that connects Python to the web.”

No comments:

Post a Comment

🚀 What is Microsoft SharePoint?

  🚀 What is Microsoft SharePoint ? SharePoint is a web-based platform in Microsoft 365 used for: Document management Team collaboration I...