Web frameworks

In the modern development of web applications, different frameworks are used, which are tools that give us a working scheme and a series of utilities and functions that facilitate and abstract us away from the construction of dynamic web pages.

In general, frameworks are associated with programming languages (Ruby on Rails (Ruby), Symphony (PHP)) in the Python world. The most well-known one is Django, but Flask is an interesting option that may not have such a high learning curve. It allows us to create web applications that are just as complex as those that can be created in Django.

A web framework is a layer that sits between the web server and our Python code, which provides abstractions and streamlined APIs to perform many of the common operations of interpreting HTTP requests and generating responses. Ideally, it is also structured so that it guides us into employing well-tested patterns for good web development. Frameworks for Python web applications are usually written in Python, and can be considered part of the web application.

The basic services a framework provides are as follows:

  • Abstraction of HTTP requests and responses
  • Management of the URL space (routing)
  • Separation of Python code and markup (templating)

There are many Python web frameworks in use today, and here's a non-exhaustive list of some popular ones:

An up-to-date list of frameworks is maintained at http://wiki.python.org/moin/WebFrameworks and http://docs.python-guide.org/en/latest/scenarios/web/#frameworks.

Some frameworks provide the minimum to quickly build a simple web application. These are often called micro frameworks, and one of the most popular is Flask. Although they may not include the functionality of some of the heavyweight frameworks, they provide hooks to allow for the easy extension of more complex tasks. This allows a fully customizable approach to web application development.

Other frameworks take a much more batteries-included stance, providing all the common needs of modern web applications. The major contender here is Django, which includes everything from templating to form management and database abstraction, and even a complete out-of-the-box web-based database admin interface. TurboGears provides similar functionality by integrating a core micro framework, with several established packages for the other features.

However, other frameworks provide features such as supporting web applications with an event-driven architecture, including Tornado and CherryPy. Both of these also feature their own built-in production-quality web servers.

Here, we have provided a small description for some of these frameworks:

  • Django: This is perhaps the most well-known web framework of Python that brings more features to its core. The main feature offered by Django is the possibility of having an interface for the administration of its applications, from which you can work with the database models and forms. At the database level, an ORM system (Object Relational Mapper) is used to relate the models declared in Django with tables in databases.
  • Pyramid: This was one of the first web frameworks that was compatible with Python 3. It is considered the best option if your target is to have a quick prototype of the website or to develop large web applications, such as a content management system (CMS).
  • Web2py: Architecturally, Web2py follows the MVC. It incorporates generated forms with validation of fields, and the sessions are stored on the server side. Database support includes built-in SQL generation for the most popular databases. Once you have defined your models, you will get a full administrative interface automatically.
  • Flask: Flask is a micro framework based on the Web Server Gateway Interface (WSGI), which is responsible for handling requests between the client and the server. It supports Jinja2 templates; a friendly, modern, safe, and popular template language that's also used by Django.
  • Plone: Plone is a framework that acts as a CMS, with functionalities that make it especially suitable for the business world. It is built on top of the Zope platform (http://www.zope.org), a well-known framework based on the Python language. Zope serves as an application server and is very popular within the Python community.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset