Flask vs. Django?

So I was going to do a Flask tutorial this week after learning it in a week, but I decided to do a comparison with Flask and Django since I've had hands-on-experience with both python web frameworks. The reason is so that I can help you choose which framework to learn as learning a framework can be very time consuming —- but very fun of course!

CAUTION: I only spent a week with Flask whereas I've used Django for the past 3 years. Take this with a grain of salt 😅

Similarities

Let's start with similarities.

1) Flask and Django are both python web frameworks.

They enable you to create web applications using python for backend logic and html and css as front, or whatever front-end framework you'd prefer.

2) Can use ORM or object-relational-mapping.

This basically means, you can use SQLITE, MYSQL, PostgreSQL, and other databases that utilizes ORM.

-Django by default uses ORM.
-Flask does not come with ORM capabilities by default. You need to manually add it if you want.

3) Templating.

-Django uses a template engine similar to Jinja (actually Jinja was inspired by Django's own templating system)

Small comment: Django doesn’t use Jinja, but it’s own templating engine. They look similar because, as Jinja’s website says, “It is inspired by Django's templating system.”

-Flask uses Jinja as its template engine.

Jinja is basically like python for html (python + html = Jinja) that enables you to add logic to your html such us if/else, for-loops, and extension of templates which I really really love!

There are many more similarities between Flask and Django, but for me those are three the main ones.

Differences

The differences are quite big when you put Flask and Django side by side.

With Flask you get incredible flexibility.

You create the app.py (which is like the main logic for your app), the models.py (which is where you store your models that creates the tables for your database), the templating and etc. You have ABSOLUTE control on how you want to build the structure for you app.

With Django, it's all built for you!

The settings.py (which is like the config file for your app) the models.py, the urls.py (which is where all the routings are stored), the templating, etc.

Which is why Django's tag is, "The web framework for perfectionist with a deadline." Because everything is built in, you don't need to bother yourself with creating the files and thinking about how you should structure your app. It's all ready for you and you can immediately get started with building your app.

Conclusion

Flask and Django both have their strengths and weaknesses.
Each one has their own uses and purposes.

If you're making an app that's simple that doesn't anything too complex, then Flask is the way to go.

But if you're a beginner and want to get into web development with python, I'd suggest you start with Flask. The things you learn in Flask can be applied to Django. It's just easier with Flask.

Congratulations 🎉🎉! You made it! I hoped it helped you out!
Also, tell me if you'd like to see me do
a tutorial of Flask or Django on Youtube.
Thanks ya'll! Have a break, take a kitkat 🍫.

Thanks for all those who gave their feedback and added stuff to my knowledge on Flask and Django! Keep 'em coming ✌🏽

I'd look at things a bit differently: Django is a complete software stack for building an application, whereas Flask is some decomposed building blocks which allow you how to pick and choose how to build your application. Flask can absolutely be used for larger things just as well as Django, it's just that Django gives you more Stuff out of the gate. But you might not necessarily want to use the stuff Django provides, or want or need the baggage of having it loaded.

Like, you might not even need an ORM, or if you do you might want to use SQLAlchemy or ponyORM or Peewee, because each of them provides a different way of interacting with your data with different tradeoffs. With Django the most reasonable choice is the one-and-only Django ORM.

Same with things like authentication; in Flask you can pick and choose your authentication mechanisms (and choose whether or not to use Flask-Login for the session management, for example), you can choose to use any number of Markdown implementations (there's Flask-Markdown but I personally use Misaka because it works closer to how I need it to), you can choose whether or not to even have an admin interface (not all apps need one, after all), and so on.

For some examples, I built my own website in Flask (well, Publ, which is built on Flask), as well as flrig.beesbuzz.biz/ as a microservice sort of thing. I also used Flask to build a purpose-specific application server for a local apartment building's Internet-driven art installation; that basically only uses Flask as a very simple request routing system (with Jinja for the page rendering, since it's convenient).

Django definitely has its uses, but it's not necessarily that it's what you should use for a larger thing. It's very much a batteries-and-kitchen-sink included framework, and I'm not particularly fond of that sort of one-size-fits-all approach.

Right! That makes sense as well! With Flask you kinda have it all in barebones and it's up to you as to what sort of blocks you want to add into it. While with Django it's all in ready for you.

So far with my one week experience with Flask, it's really all barebones. Completely flexible to what you want and need. It doesn't complicate you with the things you don't need but simply provides you with like a launchpad (figuratively speaking) to allow to make something immediately without all the complications.

With Django, it's all ready for you. The routing, the setup, the models, the templates, etc. It has it's own structure already that you don't need to bother with finding the things you may need for your project, because it's all already there.

For me personally, if you're just out there making something small I think that you should start off with Flask. Ofc, you can build something small with Django as well, but why overly complicate building your app by having to deal with Django's built in packages?

When I just started learning about web development I started out with Django and when I saw all these built-in packages that Django had, I had to learn what those do and how to deal with it. Which wasn't much of a pleasant learning experience.

The reason why I wanted to learn Flask was because I wanted to build something immediately, without making it perfect and having to deal with all the built stuff that Django has. If I only needed something, that's what I would get, and that's what Flask has enabled me to do.

is that so? maybe i didn't state it properly. you can definitely create tables using the models.py sort of like similar to django's python manage.py makemigration and python manage.py migrate. except in Flask it's python manage.py db migrate and python manage.py db upgrade

I ran through some Django tutorials as part of my exploration of the python eco system. I like how Django code is built into "pods", but there is more of a learning curve as you need to figure out everything and the kitchen sink.

I was really surprises by Falcon, don't know if you've tried it.
I think it's very nice for pure API servers, no templates there, so it fits most of my needs and I felt totally comfortable with it after 30mins and a completed backend in an hour :)

I'm going to try Flask at some stage after going through ExpressJS this weekend.

Ben, I'm glad you are engaging with these topics, and are willing to correct mistakes when they're pointed out. But do you really think you have the experience level to write this article at all? This is now publicly available, and frankly what you have here misses the mark as a discussion of Flask, Django, and any substantive comparison of the two. I can imagine other inexperienced developers reading this and making poor platform decisions based on what you've presented. I'd like to suggest you publish in areas you have expertise in, rather than angling for easy clicks on topics where you're not really ready to contribute.

I am working with both Django and Flask for more than 2 years...Although Flask is my go-to framework if I want to create any project or simple website to visualize my ML models due to its simplicity and customization(like I love to use MongoDB as my go-to database and remote availability in mlab), I agree with the fact that structuring become little bit problem if the project becomes bigger and bigger.
Said that, if you want to create something small quickly, I will suggest going for Flask. Like, when our semester results were declared recently, friends were finding it difficult to calculate overall CGPA of all semesters. So I was able to create this cgpa-calculator.herokuapp.com and host it on Heroku in just 30 mins.

Oh! Sorry, I failed to mention that. 😅 Flask on its own does not come with querying capabilities. I recall having to install flask-sqlalchemy via pip in order to do querying from my database. Thanks! 👍

True about the databases not being included by default, but i still like to use flask to customize my databases using OOP. I think its easier than getting the batteries included approach with django..personal preference.

Hi Ben,
Every python developer knows that sqlalchemy is powerful. So you are not entirely correct by saying Django orm is more powerful than flask-sqlalchemy. Anything you can do with sqlalchemy you can with flask-sqlalchemy. Once upon a time Django orm couldn't do many to many without some hacks but you could with flask-sqlalchemy. Also, flask can do a lot more than you think, so mini apps isn't entirely accurate. Flask puts more power in the developers hands because it's configurable while Django thrives on conventions.
With these frameworks, it's just a case of picking your poison. But looking at the facts, you are off to a great start.

Just few days ago I started to learn Django. I been a PHP developer(code PHP).But now I am a big Django fan. I love this framework. I was thinking that I will learn Laravel. but I don't think that I have to learn that anymore. (But still I want to say that core PHP is so easy for me)