0
0
Flaskframework~30 mins

Flask project structure conventions - Mini Project: Build & Apply

Choose your learning style9 modes available
Flask Project Structure Conventions
📖 Scenario: You are creating a simple Flask web application for a small bookstore. You want to organize your project files properly so it is easy to maintain and expand later.
🎯 Goal: Build a basic Flask project structure with the main application file, a templates folder for HTML files, and a static folder for CSS and images.
📋 What You'll Learn
Create a main Flask application file named app.py
Create a folder named templates inside the project directory
Create a folder named static inside the project directory
Add a simple route in app.py that renders an HTML file from templates
💡 Why This Matters
🌍 Real World
Organizing Flask projects properly helps teams work together and makes it easier to add features or fix bugs later.
💼 Career
Understanding Flask project structure is essential for backend web development roles using Python and Flask.
Progress0 / 4 steps
1
Create the main Flask application file
Create a file named app.py and write the code to import Flask from flask and create an app instance called app.
Flask
Need a hint?

Use from flask import Flask and then app = Flask(__name__) to create the app instance.

2
Create the templates and static folders
Create two folders named templates and static inside your project directory. These folders will hold HTML files and static assets like CSS and images respectively.
Flask
Need a hint?

Use your file explorer or terminal commands to create templates and static folders next to app.py.

3
Add a route to render an HTML template
In app.py, import render_template from flask. Then add a route for / that returns render_template('index.html').
Flask
Need a hint?

Use @app.route('/') decorator and define a function named home that returns render_template('index.html').

4
Add a simple HTML file in templates folder
Create a file named index.html inside the templates folder. Add a basic HTML5 structure with a <h1> heading that says Welcome to the Bookstore.
Flask
Need a hint?

Use a basic HTML5 template with <h1> inside the body that says Welcome to the Bookstore.