Flask Vs Django.

Which python framework should you use?

🧵👇
You must have read articles that say Flask is a 'lighter' framework than Django than Flask but what does this mean?

Let me show you.
In order to create a Django project, you run this command 👇
It generates a file and a folder within that folder.
and more files inside that folder...
You can create "apps" within your main project.

An "app" is basically a component of the larger project.
Let's say your project is about making a social media website using Django.

You'll have several different functionalities within this project like a home page, a place to make posts etc.

You can implement all these functionalities in different "apps" to keep things organised.
Another thing with Django is that you constantly have to run certain commands like "make migrations" when you add a new "app".

This can be hard to remember as a beginner but it keeps things very organised.
Django also gives you the flexibility to use any database like Postgres, MariaDB etc.

You even have built-in security features and support for authentication.

On top of all of these features, you also get an inbuilt dashboard in Django, sweet!
For a beginner, this might be a little tough. (at least it was for me)

It's a bit hard to wrap your head around all these files, folders and commands, but once you do, Django is seriously amazing and things are done in a very specific way.
Now let's talk about flask.

Things are more simple here, with no commands to start a project like Django.

You start with a single file and then you build upon it.
You can run Flask applications just like you would run a normal python file.

`python app. py`

This starts the application, in flask you use "SQLalchemy" to interact with databases and like Django you can use any database you like.
You have a lot of flexibility in Flask, which also means its slightly harder to organise.

Remember how I said that things in Django are done in a very specific way? Well, Flask is quite the opposite.

One can do the same thing in very different ways in Flask.
Flask's simplicity also means that it does not come with a lot of the features of Django like a dashboard, security features and authentication.

I think you'll realise that there's a trade-off here, simplicity(Flask) vs more features. (Django)
Both Django and Flask use a similar templating engine (basically how things are shown in the front-end) called "jinja".
Django makes sense for freelancers and big enterprises because of how "organised" it is.

An e-commerce app or a social media app is the ideal use case for Django. (Fun Fact: Instagram used Django at one point)
Flask is better suited for hobbyists, start-ups or solo developers.

Deploying machine learning applications with Flask is the most ideal use case I can think of.
(Generally) What I hear is that Django is the industry standard so that might be something to consider if you're looking for a job.

At the same time, you should also know that if you know Flask then learning Django will not be too difficult and vice-versa.
I am personally a huge fan of both of these.

Also recently I've been trying out FastAPI but I think that framework is so awesome that it deserves a thread of its own.
Another very common question I get about Django and Flask is that "Can you use React, Vue or Angular with it?".

The answer is no, at least not with any modifications like making an REST API with Flask and Django(which is why I'm so excited about FastAPI)
If you'd like to see more content like this then follow me because I have more coming.

Cheers!
You can follow @PrasoonPratham.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.