3 ms·
> Beware and use Django until you’re sure you AND your team know what you’re doing. That's one of my pet peeve in the Python world: people thinks Flask is for
by BiteCode_dev 6y ago
> Beware and use Django until you’re sure you AND your team know what you’re doing.
That's one of my pet peeve in the Python world: people thinks Flask is for beginners and Django for advanced users. The Flask API is simple, the hello world is 5 lines. By the time you render your first Django ViewModel, you have read and tried out the full Flask doc.
So it's easy to say, "I'll start with Flask, and check out this Django thing later".
But in reality, it's exactly the opposite. Flask requires you to know a lot of things and make a lot of decisions, not to mention select/write additional libraries for features Django packs.
So if you use Flask for anything non trivial, you should show your trade or you are going to mess up, big time.
If you are a beginner, you should always start with Django. Yes, it's more work up front, but it will give you an idea of how important concepts work, plug in to each others, and can be organized in a code base.
Django is not perfect, and its ORM is really far from SQLAlachemy, but it's good enough for a loads of thing. And it will be mostly secure and extensible by default.
- mrRandomGuy 6y ago100% The upfront cost of Django makes people thing it's much more complicated than a micro-framework like Flask. I like Flask, but not because it's a simple easy to use framework, especially once you chuck SQLAlchemy into the mix. Shit, even now if I don't touch it for a while I end up trying to remember how things work
- gchamonlive 6y agoIn the context of database transactions, any APIs serve only as backend endpoints. For this purpose I question whether flask is the best choice. For rest API, I always go for Falcon.
- BiteCode_dev 6y agoWhile I do keep my eyes on FastAPI, even in this case I would recommend Django to a beginner, solely because of the amazing Django Rest Framework. Not only it makes creating an API from ORM models quick and easy (although the documentation doesn't let you believe so), but it also let you do custom views seaminglessly, including goodies such as standardized permissions, authentication and pagination with several levels of granularity. Having that being able to be integrated with all the rest of the Django ecosystem transparently (your website, a wagtail CRM, etc.) is really sweet. But the biggest advantage for a beginner is again that it will prevent them from having to make decisions they are likely to get wrong. Especially on the serialization, format, identifier policy and homogeneity of the API: people crafting that by hand often make a big mess and don't even know about it.
- blackrock 6y agoIf you don’t use Django’s ORM or SQLAlchemy’s ORM, then do you really need to use Django? Like an adjacent commenter said, ORM is ok for simple blog websites. But I can’t imagine using an ORM for complex data tables and relationships with normalized data.
- BiteCode_dev 6y agoI used the Django ORM for surprisingly complex applications I created a video streaming website, with 600k visitor days, that features tagging, categories, related vidéos, user upload, encoding queue, search with auto-completion and so on. It relies heavily on the ORM. Django migration system and db model generation also make it a very nice tool for data export/migration/exploration. The ORM provides a nice API, but above all, a standardized one, which lead the Django ecosystem to become so reach because of the assumptions the libraries could do, making you very productive. Now, one has to remember: - you can, and should by pass the ORM if you need it, writing raw SQL. Django let you do that. - plenty of things can end up be in a cache, using varnish, redis, etc. Plus a lot of things should be done in task queues anyway, not in the django views. So the cost of the ORM is rarely an issue. - complex data tables are sometimes better presented using SQL views, making the ORM model simple. As usual with coding, it's a matter of gain and cost, and the right answer is "it depends". But you can go very far, and very comfortably with this tools, as long as you don't fight against its nature. So yes, definitely use Django with the ORM. I am not advocating to use Django + SQLA, but rather contrast Django with Flask + SQLA.
- darkhorse13 6y ago>But I can’t imagine using an ORM for complex data tables and relationships with normalized data. Whenever I read a statement like this from someone, I always feel that they actually haven't thoroughly read the docs for Django's ORM. Can you give me one concrete complex example that you can't imagine doing with the ORM? Because 95% of the time, these "complex" models are trivially easy to pull off with the ORM (from my experience).
- ddorian43 6y agoDjango orm doesn't support composite primary keys.