One thing Python isn’t short of is packages and Web frameworks. A visit to PyPi, the official package index, shows that frameworks alone have a whopping 12,514 packages available, with Django, Plone and Zope 2 leading the pack. Web development frameworks in Python are about as common as content management systems in PHP.
The point of a Web framework is to save you the effort of writing infrastructure code when developing a non-trivial website. Unless you have a well-funded and skilled team, it makes more sense to use code that’s already been developed and tested. Do you really want to write code for working with different types of databases, adding object relational mapping code if necessary? What about generating Web pages, managing sessions and cookies, developing admin interfaces, creating tests and worrying about all the ways hackers can defeat your code? Once you’re up to speed, Web frameworks can save you a lot of time.
Named after the legendary guitarist Django Reinhardt, this is the best known of the frameworks, with over 4,300 sites listed on djangosites. Like many Python frameworks, Django uses a Model View Controller (MVC) approach and works with all major database engines. It helps that it’s not difficult to install and set up. Django is also interesting in that it supports both Python 2.* and 3.* using the single file compatibility library six. Extensibility is one of Django’s strengths. Sites built on it include Mozilla, Pinterest and Instagram.
Is it perfect? Well, the templating isn’t considered very Pythonic and the ORM is not as good as SQLAlchemy, but it’s got a lot of happy users.
TG2 was built to try and answer frustrations surrounding TurboGears 1 and Django. It’s built on top of best-of-breed open source components including Pylons, SQLAlchemy, Genshi and Repoze. Pylons provides the controller mechanism, Genshi the view through HTML/XHTML templating and SQLAlchemy looks after the model. It’s a sophisticated ORM and is highly regarded.
TurboGears lets you create single file applications—simple examples or Web services in minimal mode—then switch to full-stack projects for a more complex website. Compared to Django, it’s a bit more flexible.
Formerly known as Enterprise Web Framework, Web2py is based on Ruby on Rails, but written in Python (2.5, 2.6 or 2.7 but not 3.*), and designed to prevent common Web security failings such as cross-site scripting.
Requiring no installation or configuration, Web2py is the simplest of the three frameworks. It’s focused on rapid development, ease of use and security, plus there’s a Web interface for handling administration. It also lets you handle admin from the operating system shell or Python shell. Included with Web2py is the SSL-enabled Rocket Web server, though it will run with Apache and other servers as well.
There’s no right answer to which framework is most appropriate for your needs. All I can suggest is that you try them out and see which you like the best. And don’t forget that these are only three of the many options available.