MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Virtual Environments & First Flask Application0%
Study Materials
FlaskProgress 0%
1.1What is Flask & WSGI Architecture1.2Virtual Environments & First Flask Application1.3Flask CLI & Environment Configuration
HomeTutorialsFlaskVirtual Environments & First Flask Application
Flask CLI & Environment Configuration

Virtual Environments & First Flask Application

Beginner12 min read•Updated: 2026-09-16•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Before building web applications with Flask, establishing an isolated virtual environment is critical. Virtual environments guarantee that your project's dependencies never conflict with system-wide Python packages or other projects on the same machine.


1. Setting Up an Isolated Virtual Environment

Python 3 provides the built-in venv module. Follow these commands in your project terminal:

On Windows (PowerShell / Command Prompt):

1# Create project workspace directory
2mkdir flask_mastery_project
3cd flask_mastery_project
4 
5# Create a virtual environment named .venv
6python -m venv .venv
7 
8# Activate the virtual environment
9.venv\Scripts\activate

On macOS / Linux:

1# Create and activate
2python3 -m venv .venv
3source .venv/bin/activate

When activated, your terminal prompt will display (.venv).


2. Installing Flask 3.x

Install the latest version of Flask using pip:

1pip install flask

To verify the installation and view installed dependencies:

1pip list

You will notice that installing flask automatically installs its key dependencies:

  • Werkzeug: WSGI utilities and routing
  • Jinja2: Template engine
  • MarkupSafe: HTML string escaping
  • click: Command Line Interface framework
  • itsdangerous: Cryptographic signing for session cookies
  • blinker: Signal dispatching (in modern Flask 3.x)

3. Creating Your First Minimal Flask Application

Create a file named app.py in your project root:

1from flask import Flask
2 
3# Initialize the Flask WSGI application
4app = Flask(__name__)
5 
6@app.route("/")
7def home():
8 return "<h1>Hello, World! Welcome to MSK Flask Mastery.</h1>"
9 
10@app.route("/about")
11def about():
12 return {
13 "status": "success",
14 "message": "MSK Institute Flask Microframework Tutorial",
15 "version": "3.0.0"
16 }
17 
18if __name__ == "__main__":
19 app.run(debug=True, port=5000)

4. Dissecting the Code Line by Line

  1. 1
    from flask import Flask: Imports the central application class.
  2. 2
    app = Flask(__name__):
  • An instance of the Flask class is created.
  • __name__ is a Python special variable representing the current module's name ("__main__" when run directly).
  • Flask uses __name__ to locate templates, static assets, and resource folders relative to this file.
  1. 1
    @app.route("/"):
  • A Python decorator that registers a URL path mapping. When an incoming HTTP GET request matches "/", Flask invokes the decorated home() function.
  1. 1
    return "<h1>...</h1>":
  • Returns an HTML string. Flask automatically converts string returns into an HTTP 200 OK response with Content-Type: text/html; charset=utf-8.
  1. 1
    return {"status": "success", ...}:
  • In modern Flask, returning a Python dictionary automatically serializes to a JSON response with Content-Type: application/json.
  1. 1
    app.run(debug=True, port=5000):
  • Starts Werkzeug's local development server on http://127.0.0.1:5000.

5. Running the Application

Execute app.py directly:

1python app.py

Console Output:

1 * Serving Flask app 'app'
2 * Debug mode: on
3WARNING: This is a development server. Do not use it in a production deployment.
4 * Running on http://127.0.0.1:5000
5Press CTRL+C to quit
6 * Restarting with stat
7 * Debugger is active!
8 * Debugger PIN: 482-192-301

Open http://127.0.0.1:5000 in your web browser to view your live web application!


Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Why is __name__ passed into app = Flask(__name__)?
Question 2
What happens in modern Flask when a view function returns a Python dictionary?
Question 3
Which command activates a Python virtual environment on Windows PowerShell?
Question 4
What is the primary purpose of the debug=True flag in app.run() during development?
Question 5
Why is the built-in app.run() development server explicitly not recommended for production deployments?
Next Lesson

Flask CLI & Environment Configuration

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
What is Flask & WSGI ArchitectureFlask CLI & Environment Configuration

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Flask with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext