Python Web Apps and Servers - robbiehume/CS-Notes GitHub Wiki

General

WSGI (Web Server Gateway Interface)

  • WSGI overview (with helpful diagrams)
  • WSGI is the standard interface that modules and containers could implement and is the accepted approach for running Python web applications
  • Why use WSGI and not just point a web server directly at an application?
    • WSGI gives you flexibility: developers can swap out web stack components for others. For example, you can switch from Gunicorn to uWSGI without modifying the application or framework that implements WSGI
    • WSGI servers promote scaling: serving thousands of requests for dynamic content at once is the domain of WSGI servers, not frameworks
      • WSGI servers handle processing requests from the web server and deciding how to communicate those requests to an application framework's process
      • The segregation of responsibilities is important for efficiently scaling web traffic

Django

Overview

  • Uses a design similar to MVC, called MVT (model, view, template)
    • The view and template in Django’s MVT pattern make up the view in the MVC pattern of other web frameworks
    • Although it’s based on the MVC pattern, Django handles the controller part itself
      • There’s no need to define how the database and views interact, it’s all done for you
  • Benefits of Django: rapid development, provides extensive library (security, sessions, authentication, etc.), it's very scalable

Flask