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 ...
For further actions, you may consider blocking this person and/or reporting abuse
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.
Maybe you should first build some applications with these frameworks, and then only afterwards start thinking about writing about it.
Through Ben's article, many of us listening are greatly benefitting! In my view,it is a great way to get the experts out of their dens!
Definitely!
The experts have already written countless guides to these frameworks, including head-to-head comparisons. Why not just find and read them?
I actually did! Though, I'll admit I did only spend a week with Flask. I've spent more time with Django and I've been using it for the past 3 years now. 😅
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.
It seems to me that you have never used Flask before. It has absolutely no database functionality whatsoever, and thus no ORM.
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
andpython manage.py migrate
. except in Flask it'spython manage.py db migrate
andpython manage.py db upgrade
There’s no
manage.py
in Flask unless you created it manually. From the website: “By default, Flask does not include a database abstraction layer”Agreed, seems like op has never truly used flask. ORM ain't part of it by default.
Oh! Thanks 😄guess I missed that part.
Granted, I did only use and learn Flask within a week so I missed quite a bit of information. Thank you for making this clear 😅
Glad I could help.
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.
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.
Woah really? Thanks Joe! I haven't really used sqlalchemy before and only really encountered it in flask-sqlalchemy.
Also my evaluation of Flask was only based on my one week experience with it along with what I've heard from fellow developers in my community. 😅
Perhaps in using Flask more I'd be able to learn more about it's capabilities and it's strengths.
Thanks man! I'll be sure to learn more about it. 🎉👍
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.
what do you mean by "Flask querying methods"?
I think it should've been querying capabilities 😅by it I meant that Flask's querying capabilities are a bit limited compared to Django.
You can refer to this link for a list of Django's Queryset API's: docs.djangoproject.com/en/2.1/ref/...
And here for Flask: flask-sqlalchemy.pocoo.org/2.3/que...
As you can see Django has more options available for you compared to Flask.
no i mean, flask does not have in-built querying capabilities.
flask-sqlalchemy is just a wrapper for sqlalchemy, a normal python orm
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! 👍
i appreciate your article though, having written it, now you know more about the matter!
Yes definitely! I've learned more about Flask and Django through it 😄 thanks for clarifying this too!
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.
Most of the time flask is used to build REST APIs but Django can be used to build that as well due to the Django packages ecosystem like Django REST Framework.
If your a beginner I would suggest them to learn Django first due to battery built-in reasons and it allows one to focus on learning the 3 tier architecture that is useful to segregation of your code.
This is a cool article, Ben. Maybe not the most in-depth (as some other commenters have pointed out), but I think it presents the most important points in a nutshell. Sometimes a short summary can be the most valuable. I notice you have mostly a developer's perspective on this subject; what about the perspective of someone who manages development teams? Someone like a Project Manager or CTO would probably make framework decisions based on different criteria, such as their budget and timeline. If anyone here would like to explore the "manager side" of this subject, here's one article I'd recommend: stxnext.com/blog/2019/05/31/flask-...
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)
What would be some good resources to start learning Django?
I started learning about Django here:
tutorial.djangogirls.org/en/
I would highly recommend it 👍
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.”
Django can definitely use Jinja as a templating language since 1.8 (docs.djangoproject.com/en/2.1/topi...)
Not arguing otherwise. The point here is to compare default behaviors between Flask and Django. You can also use SQLAlchemy instead of Django’s built in ORM if you want.
Oh! Gotcha, I'll add that in. Thanks! 👍
Flask is simple and powerful but, when I realized that I’m trying to “structure” my project, I went to Django
Lots of thanks for the article. I would greatly appreciate a flask tut.