A Beginner’s Guide to Python Web Frameworks
A web framework is a collection of packages or modules which allow developers to write web applications or services quickly, without getting into the details of network protocols or network socket programming. Web frameworks encapsulate what developers have learned over the past 20 years while programming sites and applications for the web. Frameworks make it easier to reuse code for common HTTP operations and structure the projects so that other developers can quickly build the projects with the knowledge of the same framework.
Web framework common functionality include:
- URL Routing
- Input form handling and validation
- HTML, XML and JSON and other output formats with a templating engine
- Database connection configuration and persistent data manipulation through Object Relational Mapper
- Web security against CSRF(cross-site request forgery), SQL injections and other malicious attacks
- Session storage and retrievals
Do I have to use a web framework?
How are these web frameworks different from LAMP? LAMP is a software stack containing Linux, Apache, MySQL, PHP/Python/Perl. Apache is a web server program which is a piece of software which actually runs the web applications. This piece of software is part of the web frameworks too. But the frameworks help to build the applications quickly by aligning with the project development structure, templating systems etc, so that developers focus on logic rather than packaging multiple components from scratch.
Web frameworks solve the big two: Routing and Templates
Of all the questions surrounding building a web application, two stand out:
- How do we map a requested URL to the code that is meant to handle it?
- How do we create the requested HTML dynamically, injecting calculated values or information retrieved from a database?
Popular Python web frameworks:
There are many more frameworks in python to name a few, Cherry Py, Bottle, Sanic, Tornado, Dash.
Things to consider while choosing the framework:
When deciding which framework to use, look at the size and complexity of the project. If there is a need to develop a large system packed with features and requirements, a full stack framework might be the right choice, if the app is smaller and simpler, consider a microframework. A final decision should come from your own understanding of the project and the tasks to be simplified.