Flask Introduction


Flask is a micro web framework written in Python. It’s called “micro” not because it’s limited, but because it keeps the core simple and extensible. You can build anything from a small prototype to a full-featured web application. Flask it doesn’t impose strict requirements on project structure or dependencies. Here is a list of some features.

  • Routing: Easily map URLs to Python functions using the @app.route() decorator.
  • Templates: Use Jinja2 templating to dynamically generate HTML (render_template()).
  • Request Handling: Access query parameters, form inputs, JSON data with request.
  • Modular: Add only what you need โ€” like SQLAlchemy for database handling or Flask-Login for authentication.
  • Debug Mode: Built-in development server with real-time reloading and error reporting.

๐Ÿ”น Part 1: Setup Python and Flask

โœ… Step 1: Install Python (only once)

  1. Go to the official Python website: ๐Ÿ‘‰ https://www.python.org/downloads
  2. Click the yellow download button that says “Download Python 3.x.x”.
  3. IMPORTANT: Check the box that says Add Python to PATH before clicking Install Now.
  4. When it’s done, restart your computer (just in case!).

โœ… Step 2: Open the Terminal

  1. Press Windows key, type cmd, and hit Enter.
  2. Youโ€™ll see a black window โ€” this is the Command Prompt. Youโ€™re ready to talk to your computer ๐Ÿ’ฌ

โœ… Step 3: Install Flask

In the Command Prompt window, type this:

pip install flask

Wait a moment โ€” it will install Flask. Youโ€™ll see a bunch of lines. If it ends without errors, you’re good!

๐Ÿ”น Part 2: Create Your Web App

โœ… Step 4: Create a New Folder

  1. On your desktop, right-click > New > Folder โ†’ Name it flask_hello
  2. Open it, and right-click inside โ†’ New > Text Document
  3. Rename it to: app.py (make sure itโ€™s not app.py.txt)

โœ… Step 5: Write Your Python Web App

  1. Right-click app.py โ†’ Open with โ†’ Notepad (or Notepad++)
  2. Copy & paste this code:
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello, World! This is my first web app!'

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

Click File > Save

๐Ÿ”น Part 3: Run Your Webpage

โœ… Step 6: Run Your Flask App

Back in your Command Prompt, type:

cd Desktop\flask_hello

Then type:

python app.py

You will see in the command prompt

Running on http://127.0.0.1:5000/

โœ… Step 7: View It in the Browser

  1. Open your browser (Edge, Chrome, etc.)
  2. Type in the address bar: ๐Ÿ‘‰ http://127.0.0.1:5000/
  3. ๐ŸŽ‰ Youโ€™ll see: โ€œHello, World! This is my first web app!โ€

You just ran a tiny server on your own computer. Flask gave you a webpage when you went to a URL (localhost). You can now create more routes (pages), or templates (HTML files), step by step!

Flask_Hello_World_Guide.docx

Leave a Reply