0
0
Flaskframework~10 mins

Flask project structure conventions - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Flask project structure conventions
Start Project
Create app.py
Add folders: templates, static
Add config.py (optional)
Add blueprints (optional)
Run Flask app
This flow shows the typical steps to organize a Flask project from start to running the app.
Execution Sample
Flask
project/
  app.py
  config.py
  /templates
    index.html
  /static
    style.css
This is a simple Flask project folder structure with main app file, config, templates, and static files.
Execution Table
StepActionFile/Folder CreatedPurpose
1Create main app fileapp.pyContains Flask app and routes
2Create templates foldertemplates/Stores HTML templates
3Create static folderstatic/Stores CSS, JS, images
4Add config file (optional)config.pyHolds configuration settings
5Add blueprints (optional)blueprints/Organizes routes in modules
6Run appapp.pyStarts Flask development server
7Exit-Project structure ready and app running
💡 All necessary files and folders created; Flask app runs successfully
Variable Tracker
ComponentBeforeAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
app.pyNoneCreatedCreatedCreatedCreatedCreatedCreated
templates/NoneNoneCreatedCreatedCreatedCreatedCreated
static/NoneNoneNoneCreatedCreatedCreatedCreated
config.pyNoneNoneNoneNoneCreatedCreatedCreated
blueprints/NoneNoneNoneNoneNoneCreatedCreated
Key Moments - 3 Insights
Why do we need separate 'templates' and 'static' folders?
Templates hold HTML files that Flask renders dynamically, while static holds fixed files like CSS and images. This separation helps Flask serve files correctly, as shown in steps 2 and 3 of the execution_table.
Is the config.py file mandatory for a Flask project?
No, config.py is optional. It helps organize settings but the app can run without it. This is shown in step 4 where config.py is added optionally.
What is the purpose of blueprints in Flask?
Blueprints help organize routes into modules for bigger projects. They are optional and added after basic structure, as in step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is created at step 3?
Astatic folder
Btemplates folder
Cconfig.py file
Dblueprints folder
💡 Hint
Check the 'File/Folder Created' column at step 3 in execution_table
At which step is the Flask app started?
AStep 4
BStep 5
CStep 6
DStep 7
💡 Hint
Look for 'Run app' action in the execution_table
If you skip creating the 'templates' folder, what impact does it have?
AApp will not start
BHTML templates cannot be rendered
CStatic files won't load
DConfig settings won't work
💡 Hint
Refer to key_moments about the role of 'templates' folder
Concept Snapshot
Flask project structure:
- app.py: main app and routes
- templates/: HTML files
- static/: CSS, JS, images
- config.py: optional settings
- blueprints/: optional route modules
Organize files for clarity and Flask to find resources.
Full Transcript
This visual execution shows how to set up a Flask project structure step-by-step. First, create the main app.py file where the Flask app and routes live. Then add a templates folder to hold HTML files that Flask will render dynamically. Next, add a static folder for CSS, JavaScript, and images that do not change. Optionally, add a config.py file to store configuration settings separately. For larger projects, blueprints can be added to organize routes into modules. Finally, run the app.py to start the Flask development server. This structure helps Flask find files and keeps the project organized. Key points include the separation of templates and static files and the optional nature of config and blueprints. The execution table tracks each step and what is created, while the variable tracker shows the state of each component as the project grows. The quizzes test understanding of folder roles and project setup steps.