4 ms·
I've used both Flask and Django for apps that are both simple and complex. What I have discovered, is that if I use Flask for a complex app, I need to organize
by teilo 14y ago
I've used both Flask and Django for apps that are both simple and complex. What I have discovered, is that if I use Flask for a complex app, I need to organize my code in clean components that end up looking like Django. Yes, I can do this more-or-less in a freeform manner with Flask, and even use the "one file for everything" method, but for a complex app, I wouldn't want to. It's too hard to manage.
So, in the end, I end up mimicking the basic structure of a Django project: Models, Views, Forms, Utilities, etc. Yes, different ORM, different Form library, WSGI middleware instead of context processors, etc., but all-in-all, no less complex than had I used Django. It's really to the point that I find it hardly any faster to code in Flask for all but the most basic sites.
I still use Flask for super simple projects that require no Admin interface, such as Personalized URL sites for ad campaigns. So it certainly has it's place.
- pestaa 14y agoMVC is a local maxima we found to build complex apps. Complex app will always require complex structure no matter the environment. I don't want to disagree on something I don't have much experience with, but at the same time, I'd like to hear more about how you build your projects. (In addition, considering there are two viable options for plug-and-play Flask admin interfaces, I don't know why you made it sound difficult.)
- teilo 14y agoI'm not saying it is more difficult. I'm saying that it's not any less complex by the time you put everything you need together. In other words, it's a wash, so I just use Django instead. Fewer dependencies to install, fewer helper functions to write (because many of them already exist), and more components that are designed to work together. And then there are other things such as having all of your URLs specified on one place vs. as decorators with your controllers. But that's just my personal preference.
- lucian1900 14y agoI'd say getting SQLAlchemy instead of the terrible Django ORM is enough of an advantage. However, I have also found the tools around Django's ORM to be quite useful (admin, south).
- ashconnor 14y agoYou can use SQLAlchemy with Django. The part I really like about Flask is the decorators for routes. This is how it should be, not some messy file of reg-exes.
- teilo 14y agoHehe. I prefer the regexes. More power, and I've used them for decades.
- lucian1900 14y agoYou can sort of maybe use SA with Django, except when all the apps you use depend on it and you have to use SA reflection to get at your data. Sadly, the integration is poor. I totally agree about the regexes: only a small subset of all routes will ever need regexes, and you can do it explicitly in Flask when needed.
- megaman821 14y agoSQLAlchemy has pulled so far ahead of the Django ORM in features and usablility that I hope with the Django 3.0 release they replace their ORM with SQLAlchemy. For all the basic use cases it is pretty easy to add in the Djangoisms to the SQLAlchemy ORM layer.
- andybak 14y agoI don't have the time to organize my thoughts but I would like to pipe up here and say that the it's not fair to call the Django ORM 'terrible'. It's extremely easy to learn and does a good job for a very large chunk of plausible use-cases.
- lucian1900 14y agoBut it does an absolutely terrible job for another pretty large chunk of use-cases, mostly because it's closer to objects than relations. For example, Django's ORM has no concept of explicit joins for example, which are necessary for avoiding O(n) # of queries in several cases. The only way to do it is to write SQL, whereas with SA the query is trivial to write in Python.
- antihero 14y agoThis is pretty much exactly what happened to me. I started building parts of django in Flask in my own weird way (probably complete with anti-patterns etcetera) so I thought why am I doing this when there is a team of highly skilled people dedicated to making another system to do exactly this? So now I use Django. And it is AWESOME.