Ticker

6/recent/ticker-posts

Ad Code

Responsive Advertisement

Flask Installation & Setup Guide (Windows + VS Code)

 

Flask Installation & Setup Guide (Windows + VS Code)

Purpose: This document summarizes the steps followed to install Flask, create a virtual environment, and run your first Flask application.

Step 1: Verify Python Installation

Open Command Prompt and run:

py --version

Expected Output:
Python 3.12.2

Note: We used 'py' because the 'python' command on your PC was pointing to the Microsoft Store alias.

Step 2: Create a Project Folder

Commands:

D:
mkdir flask_project
cd \flask_project

Step 3: Create a Virtual Environment

Command:

py -m venv venv

This creates an isolated Python environment for the project.

Step 4: Activate the Virtual Environment

Command:

venv\Scripts\activate

After activation the prompt changes to:
(venv) D:\flask_project>

Step 5: Install Flask

Command:

py -m pip install flask

or

pip install flask


Step 6: Open the Project in VS Code

Open Visual Studio Code.
Select File → Open Folder.
Open D:\flask_project.

Step 7: Create app.py

Paste the following code into app.py:

from flask import Flask

app = Flask(__name__)

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

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

Step 8: Run the Flask Application

Open the VS Code terminal and run:

py app.py

Expected Output:
* Serving Flask app 'app'
* Debug mode: on
* Running on http://127.0.0.1:5000

Step 9: Test in Browser

Open:
http://127.0.0.1:5000

Expected Output:
Hello, Flask!

Step 10: Automatic Reload

Because debug=True is enabled, Flask automatically reloads whenever app.py is saved.

Step 11: Stop the Server

Press Ctrl + C in the terminal.

Project Structure

D:\flask_project

├── app.py
├── venv
   ├── Scripts
   ├── Include
   ├── Lib
   └── pyvenv.cfg

Command Summary

D:
mkdir flask_project
cd \flask_project

py -m venv venv

venv\Scripts\activate

py -m pip install flask

py app.py


Enregistrer un commentaire

0 Commentaires