Another popular use case for Python is web development. In this lesson, we'll learn a little bit about the basics of how web applications work and also look at the application that we'll be building throughout this section. We'll be using Flask as our web framework for this section of the course.
Web development becomes a lot easier once you know how web requests are handled by applications in general. This is the life cycle of a request through a web application:
GET- This requests a representation of a specific resource. These requests should only receive data, not cause changes.
HEAD- It's like a
GETrequest, but only receives the headers (no response body).
POST- These submit data to the application, and usually cause a change in the application's state.
PUT- This replaces the current representation of the target resource.
DELETE- Just like it sounds, it deletes the specified resource.
PATCH- These partially modify a resource.
For our notes application, we're going to be structuring our code using the MVC pattern: Model, View, Controller. At its core, MVC architecture revolves around 3 concepts:
A common problem with MVC architecture is that people put too much logic into the controller and view portions, but we'll do our best to keep the important contents in our Model.
Flask is a micro-framework that doesn't force us to use an MVC architecture, and it really doesn't provide us with any structure for doing so, but we can achieve this distinction on our own by building our own distinct modules.