Day 8 – Building Your First Web App with Flask

Description

If you’ve mastered Python fundamentals, the next big leap in your journey as a full stack developer is building a real web application. Flask, being lightweight yet powerful, is the perfect entry point. Today, we’ll walk step by step through creating your first Flask app — from setup to running on your local machine. Along the way, you’ll learn how CuriosityTech integrates Flask into real-world projects for students aiming to become professional full stack developers.

1. Why Start with Flask?

Flask is often called the “micro” framework of Python. But don’t let the term fool you. It is minimal only in setup — in practice, it can scale from a small to-do app to powering APIs used by companies like Netflix.

  • Quick to set up.
  • Requires fewer lines of code than Django.
  • Perfect for understanding request-response cycles in web apps.

At CuriosityTech, learners are encouraged to first build something simple in Flask (like a blog or notes app) before moving to Django or full-stack integrations.

2. Installing Flask

Before starting, ensure you have Python installed. Then, create a virtual environment (good practice in any Python project).

# Create virtual environment

python -m venv venv

# Activate environment

# Windows

venv\Scripts\activate

# Mac/Linux

source venv/bin/activate

# Install Flask

pip install flask

3. Your First Flask App

Create a new file called app.py and paste the following code:

from flask import Flask

# Create Flask instance

app = Flask(__name__)

@app.route(‘/’)

def home():

return “Welcome to Your First Flask Web App – Powered by CuriosityTech!”

if __name__ == ‘__main__’:

app.run(debug=True)

Run it with:

python app.py

Open your browser at http://127.0.0.1:5000/
You’ll see:
Welcome to Your First Flask Web App – Powered by CuriosityTech!

4. How Flask Works (Request-Response Cycle)

  1. User visits your site (/).
  2. Flask matches this route (@app.route(‘/’)).
  3. View Function executes (def home():).
  4. Response is returned to the browser.

5. Adding More Routes

Let’s make the app interactive with multiple pages.

@app.route(‘/about’)

def about():

return “About Page: Flask Apps Made Simple at CuriosityTech.”

@app.route(‘/contact’)

def contact():

return “Contact us at curiositytech.in or visit us at Nagpur campus!”

Now you have multiple URLs:

  • / → Home Page
  • /about → About Page
  • /contact → Contact Page

6. Adding HTML Templates with Jinja2

Instead of plain text, let’s return HTML pages.

  1. Create a folder named templates.
  2. Inside it, add index.html:

<!DOCTYPE html>

<html>

<head>

<title>Flask App</title>

</head>

<body>

<h1>Welcome to CuriosityTech Flask App</h1>

<p>This is your first web application using Python & Flask.</p>

</body>

</html>

  1. Modify app.py:

from flask import render_template

@app.route(‘/’)

def home():

return render_template(‘index.html’)

Now Flask will render a full HTML page.

7. Hierarchical Diagram: Flask App Structure

Project/

├── app.py (Main application file)

├── venv/ (Virtual environment)

└── templates/

└── index.html

This structure grows as your app scales — later you’ll add static files, models, and blueprints.

8. Real-World Example

Imagine you’re building a student portal at CuriosityTech:

  • / = Home page with welcome message.

  • /students = List of enrolled students.

  • /contact = Contact details with phone + LinkedIn.

Even this small app gives you the foundation for bigger apps like e-commerce or blogs.

9. Infographic Idea (Described)

A 3-step infographic:

  1. Install Flask → pip install flask.
  2. Write app.py → Create routes.
  3. Run & View → Browser output at localhost:5000.

10. Best Practices While Learning

  • Always use a virtual environment.
  • Keep code modular (don’t write everything in one file for large apps).
  • Experiment with multiple routes to understand how Flask handles requests.
  • Document your project — it strengthens your portfolio.

11. CuriosityTech Insight

At our Nagpur campus and through online mentorship, many students showcase their first Flask apps as part of their GitHub portfolio. Recruiters love seeing practical projects, even simple ones like “Student Manager App” or “Flask Blog.” It proves you can move from theory to execution.

12. Conclusion

Flask offers the fastest way to go from Python basics to a working web application. With just a few lines of code, you’ve built a functioning app that can scale further. As you move forward in this series, you’ll connect Flask to databases, templates, and eventually a frontend like React or Vue. By combining this knowledge with CuriosityTech’s project-based guidance, you’ll soon be capable of deploying full-scale web applications.

Leave a Comment

Your email address will not be published. Required fields are marked *