4 ms·
If you're building a complicated, full, user-facing application, and start with Flask, you'll find yourself reinventing most of Django. Eg, a user model with p
by thraxil 9y ago
If you're building a complicated, full, user-facing application, and start with Flask, you'll find yourself reinventing most of Django.
Eg, a user model with pluggable authentication and flexible permissions model, ORM with migrations and associated automatic form generation and validation, static asset compression pipeline, CSRF and CORS protection, etc.
Yes, you can find Flask libraries to handle pretty much all of that stuff, but it's on you to pull it all in, glue it together, figure out which ones work well together, and document it for any one else who might work on your project. Especially for some of the security related things, it's definitely nice to know that those parts have been integrated and tested and audited already.
It's a tradeoff. With flask, you can get exactly the components you like; with Django, they're mostly chosen for you. If you don't like Django's ORM, you can replace it, but then you lose a lot of the advantages that come from its integration with everything else.
- vforgione 9y agoExactly this. Every production Flask project I've seen has a massive requirements file to bolt on functionality that comes built into Django. The second I realize that I need an auth system or may potentially have a DB migration, I select Django. Frankly, I don't see the attraction to _bring your own_ frameworks in most cases (though I've done it for very specialized cases). I get paid to get projects done, not to reinvent the wheel.
- thraxil 9y agoTo extend this a bit, I would consider Flask if I didn't have a relational database. Without a relational DB, you lose the ORM and most of the ecosystem that's tied to it. At that point, something lightweight and simple is appealing. In practice though, when I've been in that situation, I've found it more compelling to just drop Python and use Go instead. I guess with a use case that relied on NumPy, Pandas, Tensorflow or something Python-specific but that didn't have a UI, I might still go with Flask.
- flavio81 9y ago>To extend this a bit, I would consider Flask if I didn't have a relational database. Use the Flask-SQLAlchemy plugin. It works beautifully. SQLAlchemy is a very good ORM.
- thraxil 9y agoDid you read my original comment? My point was that if you're using Flask, you are responsible for pulling in all of those components and making sure they work together, not that there weren't good components available for Flask. I'd rather use Django if I need all of those things and want them to work together. If you don't have a relational database, Django's ecosystem advantage (much of which hinges on the ORM) isn't as strong and Flask becomes worth looking at again.
- philipov 9y agoEcosystem aside, who do you think has better ORM concepts: Django or SQLAlchemy?
- thraxil 9y agoI haven't really used SQLAlchemy in anger since about 2009. I remember it being fine but I can't really say much else about it. That said, I haven't run into any limitations of the Django ORM that have driven me to look at other ones.
- flavio81 9y agoThe "Flask-sqlalchemy" plugin, as its name implies, makes Flask and SQLAlchemy work together just fine.