My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Flask vs Django

onothoja oghenemarho's photo
onothoja oghenemarho
·Nov 11, 2019

So this is my first blog post on hashnode and why this post is more directed towards newbies in terms of web development with python it may also be of help to those who have been in the field for quite some time so definitely stick around to the end, the point of this post is to make your choice a little easier by highlighting what could be your personal preferences and which incorporates it better between these two titans. Now for the longest time I could not decide on the web tool to use for web development in python, I was constantly torn between picking Django and Flask and after a long grueling battle of choice I finally decide to go with flask, but fear not because this comparison will be as unbiased as can possibly be. Now before we get to the advantages it probably would be worth noting that I made use of Django long before I started up my journey in Flask. Alright let's get to the comparison, shall we? Now the first thing you need to consider when looking at these two frameworks or should I say one framework(Django) and one microframework(Flask) -although flask feels more like a library than a framework to me- is popularity. Their popularity is the main reason these two sticks out to those who are interested in learning web development using python as opposed to other python frameworks like Tornado and bottle.

We will start our breakdown at Django. So Django is basically a fully-fledged web framework complete with its own ORM -this is for interacting with databases for those who do not know what an ORM is- a template engine and so much more, some of which we will highlight below, so let's get right into it.

  1. Django is considered by many to be the most popular python web development framework by quite a margin, this is because it is one of the older python tools for web development, this popularity means it has a larger community than it pairs, more support more learning resources as so on.

  2. Django is a batteries-included framework, this means that it does not take much to get a Django application up and running, with a few typical steps you can set up your web application. It is normally said that it's a framework for perfectionists with a deadline. In short, because of its batteries included nature you can get more accomplished with little code. This also means you have way fewer dependencies to manage(I am talking less than three) as opposed to other frameworks or libraries where you have to manage a whole lot of dependencies

  3. A third major advantage of Django is that it is easily scale-able, which means it does not have to be a huge application from the start, you can start out small and just expand from there as the need comes up, with little hassle which in a way also makes it easier to build an MVC for you project using Django

  4. Security, the bane of humanity. One major issue that arose since the dawn of the internet is cyberspace security and while there is no such thing as a completely full proof software (if there were such a thing tech giants like Google and Amazon will not pour millions of dollars into security yearly). Regardless of the lack of absolute security, there is a level of security you can attain which ensures not just any noob hacks your site, guess what, Django addresses most of the security concerns of web applications. But that is not what the fourth notable advantage is that was just for newbies so they know to consider web security when working with web applications. So the fourth point(for real this time) would have to be testing. Django has been around for a while so it has more battle-tested code which improves its security considerably but also makes the testing way easier than most other frameworks.

Now, these are just a few of the many places Django shines and although the list grows longer, these are some of the major things to consider when learning a new tool.

Alright on to Flask! It is said by some that flask started off as a joke, well jokes on whoever the jester was cause now flask is used by millions of individuals around the world. Flask is considered a lightweight micro-framework but those are just fancy terms, in truth flask is a glorified library, yes library. If it works like a library and interacts like a library then why give it an over-**glorified name that is not for me to answer and like I said, in the beginning, this is just my opinion, the point is it works a lot like a library would.

  1. The popularity of Flask has skyrocketed in recent time and it is speculated that it will surpass Django in the not so distant future, this is due to people's love for more portable platforms, and the use of serverless technology(be careful of the name, it should not be considered literally). This means that the community of flask is on the rise as such so are the resources need for learning it, as well as the ad-dons needed to make it more awesome( and honorary mention would be flask-Restplus).

  2. Flask is good for small to large scale applications although in the course of this transition there principles to consider but flask has certainly made it easier to scale easily enough(not as easy as Django) but it more than makes up for this in flexibility. Flask believes that the developer should be the one to decide exactly how the application functions, so there are no restrictions when developing flask applications except the ones you put.

  3. When it comes to working with NoSQL databases(might want to look that up if you do not know what it means) flask is definitely the way to go, with a lot of options from flask-PyMongo to flask-MongoAlchemy, there are a variety of tools to pick from, trying this with Django would almost be a nightmare come true. Flask also has support for SQL type databases.

  4. Do you plan on integration machine learning into your app at any point, well flask is definitely the way, although I have not personally tried this out it is easy to deduce that because of the flexibility flask offers this becomes an easy fix.

  5. Flask is generally faster than Django because of its minimalist design, but the fun doesn't end there; due to the general nature of Flask applications there is less the secure so it handles security pretty well(again there are libraries available for that) albeit quite different from how Django handles

Like in the Django instance, Flask has a lot of advantages I have not covered in this post, but I have covered some of the major things you would want to consider when choosing between these two

# Conclusion Personally I have always liked to see the way things interacted, and I do enjoy flexibility in my code if I can afford the time so I chose Flask However, if you needed to whip up a web app and I had a limited time, Django is probably what you would want