Choosing Python Web Frameworks: Django and Flask

If you’re getting into Python for the first time, chances are you’ve researched various web frameworks. If not, click on over the Python wiki and start browsing the expansive variety of web frameworks. Go ahead; we’ll wait.

Overwhelming, isn’t it? Do you choose the most popular full-stack frameworks or do research to find what works best for your needs? It’s tough because Python web frameworks can fall anywhere on a spectrum from executing a single-use case to providing every known feature available. With names like Flask, Django, Tornado, Diesel, Pecan, and Falcon—how do you know where to start?

What are web frameworks, and why do they matter?

Let’s begin by making sure we’re all on the same page here. A web framework is a collection, or library, of packages or modules that makes your life easier when building scalable, reliable, and maintainable web applications. Frameworks make it easier to reuse code for common HTTP operations. Basically, these frameworks encapsulate the work that developers have learned over the last twenty years while programming applications and sites. Say good-bye to protocols, sockets, and process thread management.

Django and Flask: A gritty 80s action movie?

Did you ever see Tango & Cash? It’s a buddy cop action film from 1989. No? Ah, well—it wasn’t very good. Saying “Django and Flask”  aloud reminded us of that movie. You know what? Tango and Cash is much like Django and Flask. Hear us out.

Tango and Cash are two narcotics detectives from different sides of Los Angeles who approach problems completely differently, but both manage to get the job done. Disciplined and pristine, Ray Tango (Sylvester Stallone) is a put-together police officer—the total package some might say—who is determined to go by the book. Gabriel Cash, on the other hand, (Kurt Russell) is looser, freer, and plays by his own rules. See where we’re going with this? No? Fine . . . moving on.

Django’s pros and cons

Django is commonly called a “batteries-included” framework approach—or the
“framework for perfectionists with deadlines.” This means that Django makes it easy for Python developers to dive into web applications quickly without requiring forethought into the app’s infrastructure ahead of time. Basically, build better web apps, more quickly, with less code. Django is established, has excellent documentation, and a large online community. One blogger said, “Pirates use Flask, the Navy uses Django,” which feels far more descriptive than does our perfunctory Tango & Cash analogy.

Pros

  • Well-established software with many plugins
  • Admin area out of the box makes dev and production of CMS very easy
  • ORM support
  • Clear and defined MVC organization
  • Highly customizable
  • Forms framework
  • Simple database management

Cons

  • Feels like too much software for small projects
  • Template errors fail silently by default
  • A process only handles a single request at a time
  • Deep learning curve
  • Overwhelming features

 Flask’s pros and cons

Flask is a relatively young framework, only in use since 2010. Flask is considered more “Pythonic” than Django is simply because Flask web application code is, in most cases, more explicit. Flask is the choice of most beginners due to the lack of roadblocks to getting a simple app up and running.

Pros

  • Extremely flexible
  • Minimalist without sacrificing power
  • Simple to learn and use
  • Routing URLs is easy
  • Small core and easily extensible

Cons

  • Not async-friendly
  • Limited support and documentation
  • Lack of database/ORM/forms
  • Truly limited in features

Why not choose both?

Well-rounded developers are adept with both Django and Flask. A common route is to begin building small, fun projects with a simple framework, like Flask, and move on to Django as you begin to grasp the basics. At Coding Dojo, we teach three full stacks—beginning with the full Python stack that covers both Flask and Django in detail.

Resources

Here are a few things we stumbled on that might help you determine which web framework to choose:

 

 

dojo guide

Looking for a Career in Web Development?

Read our quick-start guide to becoming a Developer

  • Includes exclusive insight from a seasoned Web Developer
  • Uncovers the top career misconceptions holding you back
  • Highlights the must-have qualities all employers require
  • 89,615 downloads to date

One thought on “Choosing Python Web Frameworks: Django and Flask

  1. Great article. I agree with the above pros and cons. Django is a well-polished framework aimed at rapid deployment and development of various web apps written in Python; this framework is distributed as an open-source.
    Opposite to Django, oriented at providing an out-of-the-box product with ready solutions for each task, Flask works more like a LEGO set, where you can construct anything you wish, using a huge set of external libraries and add-ons. Flask philosophy is “web development, one drop at a time”.
    I also find an interesting article about Python vs Flask http://ddi-dev.com/blog/programming/django-vs-flask-which-better-your-web-app/. I’m waiting for your opinion.

Leave a Reply

Your email address will not be published. Required fields are marked *


nine × = 27