A web framework is a code library that makes 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 programming sites and applications for the web. Frameworks make it easier to reuse code for common HTTP operations and to structure projects so developers with knowledge of the framework can more quickly build and maintain the application.
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:
- URL routing
- HTML, XML, JSON, and other output format templating
- Database manipulation
- 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 as 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.
General web framework resources
- “What is a web framework?” by Jeff Knupp is an in-depth explanation of what a web framework is and their relation to web servers.
- Check out the answer to the “What is a web framework and how does it compare to LAMP?” question on Stack Overflow.
- Frameworks is a really well done short video that explains how to choose between web frameworks. The author has some particular opinions about what should be in a framework. For the most part I agree although I’ve found sessions and database ORMs to be a helpful part of a framework when done well.
- Django vs Flask vs Pyramid: Choosing a Python Web Framework contains background information and code comparisons for similar web applications built in these three big Python frameworks.
- This Python web framework roundup covers Django, Flask and Bottle as well as several other lesser known Python frameworks.
- This fascinating blog post takes a look at the code complexity of several Python web frameworks by providing visualizations based on their code bases.
- What web frameworks do you use and why are they awesome? is a language agnostic Reddit discussion on web frameworks. It’s interesting to see what programmers in other languages like and dislike about their suite of web frameworks compared to the main Python frameworks.
Web frameworks learning checklist
- Choose a major Python web framework (Django or Flask are recommended) and stick with it. When you’re just starting it’s best to learn one framework first instead of bouncing around trying to understand every framework.
- Work through a detailed tutorial found within the resources links on the framework’s page.
- Study open source examples built with your framework of choice so you can take parts of those projects and reuse the code in your application.
- Build the first simple iteration of your web application then go to the deployment section to make it accessible on the web.