I created web sites for a living for 20 years.
I have become obsessed with Python.
This being the case you might think that I have jumped headlong into using Python to create a website.
That, however, is not the case.
I have approached Python’s web site frameworks with trepidation. While some of the biggest sites on the interwebs today use Python ( Instagram, YouTube, etc.) as a back-end, launching a Python powered site is much more involved than say launching a PHP powered site. The more I thought about it, the more I wanted to leverage my excellent xhtml and css skills with my newly acquired Python chops.
Python Websites – Flask vs. Django
Flask and Django are both frameworks for creating websites with Python. That is where the similarities end. The best way to think about these frameworks is that Flask is a microframework that does one thing and tries to do it well. Django is a high-level Python Web framework that tries to make sure you have everything you need to launch a modern website.
Before I started studying these frameworks I was foolishly under the impression that I would learn one or the other. That way I could specialize in one Python web framework and become l33t. It quickly became apparent that while I could choose to specialize in one or the other each framework had it own strengths and weaknesses. There are circumstances where Django would be appropriate, and others where Flask might be a better choice.
So I ended up spending a good amount of time with them both.
The Flask Microframework for Python
Flask is a BSD licensed web framework based on Werkzeug, Jinja 2 and good intentions… It’s simple to set up, comes with a built-in development server and debugger, is 100% WSGI 1.0 compliant, and is extensively documented.
Flask will not make decisions for you. Unlike Django flask does not have a database abstraction layer, form validation, a back end admin or many other services that are present in modern websites. While you can certainly roll your own services for your Flask website you will find that there are extensions so you don’t have to.
The Django Web Framework for Perfectionists with Deadlines
Django on the other hand comes with a number of these services built in. Batteries included, if you will. Django is also free and open source. It is ( surprisingly ) fast, relatively secure, and was created with scaleability in mind. If you are interested in building out a real world web app with Python for public consumption, Django is the safer bet.
Out of the box Django gives you an admin section, a caching framework, and a syndication system. On the security side it helps eliminate common security holes such as SQL injection, cross-site scripting, cross-site request forgery and clickjacking. Combined with the user management authentication system Django’s built in security makes it harder to make common security mistakes while writing your app.
Flask and Django in Depth
Over the next few days I will be publishing posts on both of these frameworks individually. They both can use jinja2 for templating, so no mater which framework you are working with you can’t go wrong learning about jinja2. Of course you can change the template systems if you want – in Django you can even use multiple templating systems in the same project…
I will also be releasing some templates that I have created ( suitable for either framework ) that you can use in your projects. While there are a number of good tutorials for the frameworks, there is a dearth of quality xhtml/css for them. Subscribe to make sure that you are notified when they are released.