Python Web Frameworks


For a few years now, in my spare time I’ve been learning Python by poking around with Python based web frameworks. Web frameworks for Python range broadly from quick set-up to complete freedom in customization. There is also a notable difference in the communities and the rate of development surrounding Python frameworks.

Flask

A lightweight micro-framework, Flask is made for customization. The freedom of customization lends itself well to large projects when there would be many custom features not available in other frameworks. The lightweight is particularly great for very small projects that do not need the standard features included in the larger frameworks. Flask is also useful for learning Python and database schema and queries as there is very little magic with the most basic functionality left to you to learn, understand, and create.

The bare bones approach of Flask doesn’t necessarily mean you have to do everything from scratch though. The Flask community has developed a number of useful extensions for basic features like user account management, admin interface, and database support.

The community is smaller than most large web frameworks but succeeds in quality. Flask and all of the available extensions are freely licensed under the three clause BSD license or other compatible free licenses. Documentation throughout the community is well written and thorough, more so than many framework communities I’ve come across.

A notable community member is Miguel Grinberg who wrote a great Flask tutorial in 2012 that got me started with Flask. Since then he has written Flask Web Development, a book published by O’Reilly. In 2017 he ran a successful Kickstarter campaign to write an updated Flask tutorial that is available in ebook and print and for free on his blog.

Django

With the largest community of Python web frameworks, Django has a lot to offer. Django has many features available out of the box including an ORM, user management, and an admin interface which allows for quick development for simple projects. You can seriously get a quick project up and running within a few hours.

On top of the features Django provides there are also a wide array of packages to quickly extend and add to your project. Django and thousands of community developed packages are freely licensed under the three clause BSD license or other compatible free licenses.

Django has a number of CMS packages that make it easier to get a basic blog or company website live. A few I have tested are Mezzanine, Django CMS, and Wagtail. I was blown away with how Wagtail CMS completely redesigned the admin interface for a much more elegant CMS experience.

One catch with Django is that Python beginners may find that it is sometimes confusing why or how something works in Django. I ran into this early on, a few years back, and is one of the reasons I worked with Flask for some time before returning to Django. Some of this concern is now covered by the massive amount of documentation that the Django project provides. However, the amount of things Django can do can be overwhelming for a beginner. This is where the community comes in.

The Django community is prolific in generating a constantly growing selection of available learning resources in tutorials, classes, videos, and books. A notable resource, Django Girls, helps organize Django workshops around the world and provides what I think is the best tutorial for Python and Django beginners. Another reference to get once you’re past the initial tutorials and beginner stage is Two Scoops of Django by Daniel and Audrey Roy Greenfield. Two Scoops is a must have reference for many of the more complicated or unclear aspects of developing and deploying Django projects.

Other considerations

Flask and Django are both great web frameworks each with their own features worth exploring. I would highly suggest giving both a try, even if just by running through their quick tutorials: Django and Flask. If you want to look elsewhere in the Python community, there are more Python web frameworks worth also giving a glance, including: