Appendix A. Python Web Development Fundamentals

It’s All HTTP Underneath

When you are working with web applications, every operation is ultimately reduced to a series of requests and responses between the user’s browser and the server hosting the application, using the HTTP protocol. While an introductory discussion of HTTP is outside the scope of this book, it’s important for web developers to know how it works.

From a web application standpoint, HTTP means getting requests from a web browser for some URL that the application knows how to handle, then processing this request and sending a response back. This sounds easy, but there’s lots of stuff to do.

Imagine that we are writing an application that will do all this work without depending on other libraries or frameworks. Our application needs to know how to interpret a request, decode any parameters that it contains, pass that information to the specific code in the application that is supposed to be run for that URL, get a result (preferably a nice HTML page with a beautiful design), encode that into a response, and send it back to the server. All of this would require writing code to handle each task.

Additionally, HTTP is a stateless protocol, which means no session information is kept from request to request. Our application will need some way to know if a user logs in or out, and make sure that the correct information for each user is used where required. The browser provides some tools to keep track of that on ...

Get Python Web Frameworks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.