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

  • Uses a design similar to MVC, called MVT (model, view, template)
  • Benefits of Django: rapid development, provides extensive library (security, sessions, authentication, etc.), it's very scalable

Components:

  • Apps: At the heart of every Django website is apps, which are small pieces of the project that make up the entire website
    • Apps typically contain some kind of database models, URLs, views, and other info about about a particular part of the website
  • Views: functions that are in charge of processing a users request when they visit a certain URL or endpoint on the website.
  • URL Routing: to handle URL routing in a Django app, you create URL patterns in a list and attach different paths to those views
    • This is how Django knows which view to fire off when a user visits a URL on the website

Flask

  • d