Fork me on GitHub

Web frameworks

A web application framework is a code library that make a developer's life easier when building reliable, scalable and maintainable web applications.

Why are web frameworks necessary?

Web frameworks encapsulate what developers have learned over the past twenty years while building dynamic web applications. Frameworks make it easier to reuse code for common HTTP operations and to structure your code so that it is maintainable.

Common web framework functionality

Frameworks provide functionality in their code or through extensions to perform common operations required to run web applications. These common operations include:

  1. URL routing
  2. HTML, XML, JSON, and other output format templating
  3. Database manipulation
  4. Security against Cross-site request forgery (CSRF) and other attacks

Not all web frameworks include code for all of the above functionality. Frameworks fall somewhere between simply executing a single use case and attempting to be everything to every developer with increased complexity. Some frameworks take the "batteries-included" approach where everything possible comes bundled with the framework while others have a minimal code library that plays well with extensions.

For example, the Django web application framework includes an Object-Relational Mapping (ORM) layer that abstracts relational database read, write, query, and delete operations. However, Django's ORM cannot work without significant modification on non-relational databases such MongoDB. Some other web frameworks such as Flask and Pyramid are easier to use with non-relational databases by incorporating external Python libraries. There is a spectrum between minimal functionality with easy extensibility and including everything in the framework with tight integration.

Django

Django is a widely used Python web application framework with a "batteries-included" philosophy. The principle behind batteries-included is that the common functionality for building web applications should come with the framework instead of as a separate library. For example, URL routing, a templating system, object-relational mapper, and database schema migrations (as of version 1.7) are all included with the Django framework.

Django resources

Flask

Flask is a Python microframework deliberately built with a small core and easy-to-extend philosophy. Flask is generally considered more Pythonic than Django because Flask web application code is often more explicit. Flask was also written several years after Django and therefore learned from the Python community's reactions as the framework evolved. Jökull Sólberg wrote a great piece articulating to this effect in his experience switching between Flask and Django.

Flask resources

The 18-part Flask mega tutorial is an absolutely amazing starting resource for using the Flask framework. Yes, there are a lot of posts in the series. However, each post is focused on a single topic to contain the complexity while the reader is learning the framework. The whole series is well worth an in-depth read-through. The author is also writing the O'Reilly Flask Web Development book so consider picking that up as well.

Bottle

Bottle is a WSGI-compliant single source file web framework with no external dependencies except for the standard library included with Python.

Bottle resources

Web Framework Resources


Next read the application dependencies section.