Python Flask Tutorial: Full-Featured Web App Part 1 - Getting Started
Based on Corey Schafer's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
Flask is used to build a blog-style app with user management, password resets, profile picture uploads, and post create/update/delete features.
Briefing
Flask is set up as a practical path to building a full-featured blog-style web app—complete with user registration and login, password reset emails, profile picture uploads with automatic resizing, and create/update/delete post management—so the learning payoff is tied directly to real application needs like databases, form input, file storage, and email sending. The tutorial frames the series around that end goal, then immediately shifts to the fundamentals: installing Flask, creating a minimal app, defining routes, and running the development server in a way that supports fast iteration.
After installing Flask via pip and verifying the import works, the walkthrough creates a new project directory (named “flask blog”) and a starter file (“flaskblog.py”). Using Flask’s simplest example, it instantiates an app object and defines a root route (the “/” path) that returns “hello world.” The tutorial emphasizes how Flask uses the special double-underscore __name__ variable to locate templates and static files, and it clarifies the role of the route decorator: it maps URLs typed into the browser to Python functions that return the content for each page.
Running the app requires setting an environment variable so Flask knows which module to serve. On macOS/Linux, that’s done with export FLASK_APP=flask_blog.py (with the transcript using “flask_app” naming), while Windows uses set instead of export. Once FLASK_APP is set, the server starts with flask run and listens on 127.0.0.1:5000. The tutorial also notes that localhost is an alias for 127.0.0.1, making URLs easier to type.
When the code changes (for example, wrapping “hello world” in HTML <h1> tags), the server must restart unless debug mode is enabled. The tutorial demonstrates two approaches: (1) set FLASK_DEBUG=1 and run flask run again so changes reload automatically, and (2) alternatively run the module directly with python flaskblog.py after adding an if __name__ == '__main__' block that calls app.run(debug=True). Debug mode is presented as the key workflow improvement for development.
Finally, the tutorial expands routing beyond the home page by adding an “/about” route. It shows how missing routes produce a 404 Not Found response, then fixes it by defining the about function and decorator. It also demonstrates that multiple URL paths can map to the same function by stacking decorators—such as serving the home page at both “/” and “/home.” The segment closes with a roadmap: the next step is returning more complex HTML using templates and passing variables into those templates.
Cornell Notes
The tutorial builds a minimal Flask application and then grows it into a multi-route setup. It starts by installing Flask, creating a project folder and a “flaskblog.py” file, and defining a Flask app instance plus a root route (/) that returns content. It explains how Flask knows where to find templates/static files using the __name__ variable, and how route decorators map URLs to Python functions. For development workflow, it contrasts restarting the server after code changes with enabling debug mode (FLASK_DEBUG=1) for automatic reloads. It then adds an /about route, demonstrates 404 behavior for undefined routes, and shows how multiple routes can share the same function via stacked decorators.
What are the minimum steps to get a Flask app running locally, and how does Flask know which file to serve?
How do route decorators connect browser URLs to Python functions?
Why did HTML changes not appear immediately after editing the code, and how does debug mode fix that?
What does a 404 Not Found mean in this Flask routing context?
How can multiple URL paths display the same page content in Flask?
What’s the role of if __name__ == '__main__' and when would someone run Flask this way?
Review Questions
- When you change the Flask route’s returned HTML, what determines whether you must restart the server or whether the change appears automatically?
- How does Flask decide which function to call for a given URL path like “/about” or “/home”?
- What is the practical difference between starting the app with flask run (using FLASK_APP) versus running python flaskblog.py (using if __name__ == '__main__')?
Key Points
- 1
Flask is used to build a blog-style app with user management, password resets, profile picture uploads, and post create/update/delete features.
- 2
A Flask app is created by instantiating a Flask object and defining routes with @app.route decorators that map URLs to functions.
- 3
Setting the FLASK_APP environment variable tells flask run which module to serve, with export on macOS/Linux and set on Windows.
- 4
The development server runs locally on 127.0.0.1:5000, and localhost can replace 127.0.0.1 in URLs.
- 5
Without debug mode, code edits require stopping and restarting the server for changes to appear in the browser.
- 6
Enabling FLASK_DEBUG=1 allows automatic reloads so edits show up after a refresh without manual restarts.
- 7
Undefined routes return 404 Not Found until a matching route decorator and function are added, and multiple routes can share one function via stacked decorators.