9 ms·
Flask vs. Django: Worksheet to choose the right framework
- dalke 12y ago> Pirates use Flask, the Navy uses Django. WakaTime is a pirate I don't understand this. According to Netcraft, the US Navy uses Active Server Pages and the UK Navy uses ASP.NET. While there could be Django somewhere in there, there's likely also someone in the US Navy using Flask. I wasn't able to find a source which says that US Navy has decided to use Django for most of its web development - I think it would be pretty surprising for the US Navy to switch to Python over a more traditional enterprise solution! More likely this is some pop culture culture reference I don't get. Anyone care to explain?
- ubernostrum 12y agoIt's the sort of thing someone says when they think they're an uber-l33t lean agile stealthy ninja rockstar webdevops disruptive buzzword buzzword, in my experience.
- jhgg 12y agoI don't think the title refers to the actual US Navy, but rather a "navy" vs "pirates" (as in people who use boats and occupy the open waters). The idea being that Django is more structured and much larger (as a navy usually is), where as Flask is smaller, etc...
- tosh 12y agohttp://www.folklore.org/StoryView.py?story=Pirate_Flag.txt http://www.folklore.org/StoryView.py?story=Pirate_Flag.txt
- jklein11 12y agoNot sure why this got downvoted... It 100% answers the question posed. Thanks Tosh!
- dalke 12y agoAhh! Yes, that's a perfect match for the given context. Thanks! I question the assertion "Django is older and larger, but Flask has a more active community according to GitHub." Surely the number of stars and watchers don't mean that those people are active in the project. According to the github pulse reports for the last month: > Flask (March 23, 2015 – April 23, 2015): Excluding merges, 19 authors have pushed 23 commits to master and 69 commits to all branches. On master, 16 files have changed and there have been 340 additions and 43 deletions. > Django (March 23, 2015 – April 23, 2015): Excluding merges, 124 authors have pushed 189 commits to master and 608 commits to all branches. On master, 2,395 files have changed and there have been 25,689 additions and 84,146 deletions. By those numbers it seems that Django has a much more active community, in the sense of making code changes. There are other types of activity than code commits, like support, conferences, etc. I don't get the sense that Flask is more active there either. Edit: If it is meant as an allusion to the Mac/Apple][ era at Apple then activity is a poor measure - there was much more activity and general interest in the Apple ][ during the Mac development.
- pyre 12y agoPart of the problem with comparing commits is the Django is more comprehensive. There is a larger "surface area" to make changes to.
- dalke 12y agoThe question really is, what's a useful way to determine which of two projects has a "more active community according to GitHub"? Is the number of stars/watchers a good enough proxy to use for decision making? The projects I use are typically quite small, and my code is on Bitbucket, so I have effectively no experience in this.
- andybak 12y agoYeah. According to this Django is for enterprisy play-it-safe noobs. Hmmmmm.
- welder 12y agoAuthor here. The Pirate/Navy title is a metaphor to say Django is rigid and Flask is flexible. You have to do things the Django way. With Flask, you can customize it easily. P.S. My cofounder Priyanka said the Pirate Navy line thing when reading the post, and I thought it was an awesome title :)
- pritianka 12y agoHehe, yes I remember saying it. Wasn't meant to be literal :-)
- collyw 12y agoWhile I agree with this to an extent (I use Django on a daily basis) Django is pretty flexible. If your app falls outside of a certain set of assumptions I would go for Flask (which I considered for a project we are working with). I would say that Flask apps need to be doing something special before Django is not considered.
- andybak 12y agoThis bit: > Flask > Django for APIs. For example, a nested api resource in Flask is > @app.route('/users/<string:user_id>/teams/<string:team_id>', methods=['GET', 'POST']) > while with Django REST framework this is impossible. > (drf-nested-routers helps but breaks unless you use only the most basic Django REST framework features. Is this really true? For a start I've managed to build a complex app without needing nested routers (although they are cool). Second - I've used DRF extensions nested routers without finding any problems. For me needing an API is a point in favour of using Django for a lot of use cases - you get an elegant declarative syntax and lots of batteries included.
- jhgg 12y agoIt's not true at all. I've done nested routers in DRF plenty of times. router = DefaultRouter() router.register('users/(?P<user_id>\d+)/teams', UserTeamViewSet) You can then access user_id via self.kwargs['user_id'] from within the viewset. And the team ID is implicitly added by the router to support list (and update), and retrieve (delete, put, patch) methods. user_id is also passed as a kwarg to the dispatched method (create, retrieve, etc...)
- asmosoinio 12y agoI don't get it either. The route definition is just an url with two arguments, right? Maybe I'm missing something...
- mpdehaan2 12y agoI ended up extending DJRF to do nested collections, but I'd argue your REST topology would be better with one canonical resource and unique team IDs: /teams/<id>/ It's fine to be able to add a user to a team by posting to a subcollection though, but there should only be one URL for the resource (IMHO).
- welder 12y agodrf-nested-routers only works with the most basic Fields. For example: https://github.com/alanjds/drf-nested-routers/issues https://github.com/alanjds/drf-nested-routers/issues Right now it's a hack that limits your api features, but might change in the future.
- therealdrag0 12y agoI can't access the site. Is it down? Blocked? Anyone have a mirror?
- welder 12y agoAlternative url: https://github.com/wakatime/wakatime-blog/blob/master/posts/25-pirates-use-flask-the-navy-uses-django.md https://github.com/wakatime/wakatime-blog/blob/master/posts/... The page loads for me just fine.
- andybak 12y agoI always fall back on my bastardized version of Greenspun's Tenth Rule. In most real-world projects started using Flask - you end up reimplementing half of Django badly by the time you're finished.
- neurosnap 12y agoInteresting, I take the opposite approach: As your project starts to grow, you end up ripping out the "batteries" of django and implementing other modules. The most notable one would be SQLAlchemy.
- rlander 12y agoYup. I switched to Flask mostly because I always ended up ripping Django apart: - Jinja instead of Django templates. - Custom (and sane) class-based views instead of Django's disgusting defaults. - Custom class-based settings. - There's no way to define app-only middleware in Django. Flask blueprints make it trivial. However, 10 years later and no framework has come close to Django's true strength: built-in admin.
- mtbcoder 12y agoYou don't have to use Django's class-based generic views either. Nothing wrong with just inheriting from the base View if you really want.
- emidln 12y agoYou can also just skip the infinite inheritance and implement function-based views.
- Igglyboo 12y agoJust an FYI, the newest version of Django (1.8) now supports Jinja or Django templates by default and you can plugin other templating engines if you want.
- mpdehaan2 12y agoOne of my more favorite reasons to use Django would be - http://www.django-rest-framework.org/ http://www.django-rest-framework.org/ - whose discoverable API browser is awesome and saves so much time in building out a great REST API with pagination, related resources, and so many other things (plus you can post from the API browser). A bit less so the built-in admin features, which are also nice at times. Possibly also the migrations system. I don't use Django templates, but the rest of it are pretty much great. I almost started a very major project with Flask, but am glad I did not for how much work DJRF and South had saved.
- thruflo 12y agohttp://python-eve.org/ http://python-eve.org/
- mjfisher 12y agoFor those who want a little context in-thread: "Eve is an open source Python REST API framework designed for human beings. It allows to effortlessly build and deploy highly customizable, fully featured RESTful Web Services. Eve is powered by Flask, Redis, Cerberus, Events and offers support for both MongoDB and SQL backends [*]."
- collyw 12y agoI'll admit I have no idea about Eve, but having used Tastypie, the beauty of Django Rest Framework is its consistency with Django. The Serializers are very similar to forms, and the API views are very like Djangos generic class based views.
- emidln 12y agoYou could also use a Django Form to validate the data with Tastypie[1]. [1] - https://django-tastypie.readthedocs.org/en/latest/validation.html#formvalidation https://django-tastypie.readthedocs.org/en/latest/validation...
- 12y ago
- waterside81 12y agoFor Python users looking for a very slim framework to build your API on, I'd highly recommend falcon https://falcon.readthedocs.org/en/latest/ https://falcon.readthedocs.org/en/latest/ It's built by the folks at Rackspace and it's super fast because you can build it using Cython and because it's just a very thin layer over wsgi. We switched over to it from Django and saw a 10x improvement in response time.
- catshirt 12y agoDjango/Rails/etc are kitchen sinks. they are not optimized for "building an API", or speed for that matter. it's kind of silly to expect them to perform as well.
- waterside81 12y ago100% agree, but since they're so ubiquitous, I'm sure quite a few people out there do so without thinking twice.
- catshirt 12y agoyou're right, i hope i didn't sound argumentative. i should clarify my own point too, and add that just because they are not "built for it", or are slower, doesn't mean they are inherently a bad choice either. it's really just what you need to optimize for. so many ways to skin a cat...
- ryannevius 12y agoThe questions and answers, for anyone who wants a summary: 1. Have you been coding for more than 5 years? (yes:'Flask', no:'Django') 2. Have you coded in Python for more than 3 years?(yes:'Django', no:'Flask') 3. Do you like reading Python code? (vs reading docs)(yes:'Flask', no:'Django') 4. Will you have an API? (yes:'Flask', no:'Django') 5. Will your site primarily have dynamic HTML pages? (yes:'Django', no:'Flask') 6. Will you use Service Oriented Architecture (SOA)? (yes:'Flask', no:'Django') 7. Using an SQL database? (yes:'Django', no:'Flask') 8. Want new devs to already know your conventions? (yes:'Django', no:'Flask')
- aprdm 12y agoWhat about Pyramid?
- ianamartin 12y agoPersonally, I like pyramid as a middle-ground between the two. More to get you started quickly a la Django; less to get in your way as you grow like flask. It tends to hit my needs right on the spot.
- mixmastamyk 12y agoThis part seemed odd: Flask serves JSON responses slightly faster than Django. Flask: 60k Django: 12k A 5x increase is slightly? Yes there is another slide zoomed out showing other frameworks much faster, but still, I'd take 5x over a poke-in-the-eye with a sharp stick if I cared at all about performance.
- welder 12y agoMy point was, saving dev time and building faster is so important that it outweighs a slow framework.
- pritianka 12y agoI agree. I felt welder downplayed the increase but I am not too experienced of a dev ...
- testguy34 12y agoThose numbers are meaningless without knowing what the code is doing.
- lucasmullens 12y agoIt says on the site, but it's basically just a "hello world" json response, so its just comparing the overhead for each web request.
- deleted 12y ago[deleted]
- pcthrowaway 12y agoAnd WSGI serves 12 times as many as Flask! /s
- chdir 12y ago> Complicated SQL queries are a piece of cake with Django's built-in ORM. I disagree here or maybe "complicated SQL query" means something entirely different to me. I've found the ORM to be great for straightforward to reasonably involved queries. However the moment you start trying to improve the database performance, you need to drop to SQL. It's another story that SQL is a lot more difficult to maintain and not very DRY across modules.
- Walkman 12y ago"It's a tie! Read about Django vs Flask to make your own choice." Thanks, this really helps a lot! LOL
- Spiritus 12y agoPerhaps a bit off topic, but what's the reason Flask hasn't had a release in almost 2 years?
- Walkman 12y agobecause Armin Ronacher (aka the_mitsuhiko here, the creator) doesn't use Flask that much any more, and there are not ver much contributors to it
- cranklin 12y agoProbably because most of the commonly used components are maintained separately.
- Spiritus 12y agoSure, but there's been almost 700 commits. There must be something in there worth a release.
- rockdoe 12y agohttps://github.com/mitsuhiko/flask/issues/1272 https://github.com/mitsuhiko/flask/issues/1272
- freework 12y agoI've been using django pretty much since 1.0 came out. Every project I start these days thats a web project, I use django. The main reason why I use django is because o the ORM and the admin. If I were to do a project in Flask, I'd have to build mt own admin, and i'd have to use SQLAlchemy. I had to use SQLAlchemy once for a project and I hated it.The django ORM is much more straigh forward an easier to use, in my opinion. In my 10 years of using django ORM, I have had to "break out of the ORM" maybe once.
- IndianAstronaut 12y agoHow do you manage with just one primary key column allowed by the ORM?
- andybak 12y agoSome people argue that composite primary keys are an anti-pattern. They might be relationally pure but they make other things a lot harder. I have a hunch that uuid's or other non-semantic primary keys are a good example of of 'practicality beats purity'.
- nyddle 12y agoWhat about Python 3 adoption? Django feels a much safer bet in this regard.
- dorfsmay 12y agoI wish they added bottle.py [1] to the mix... I'm a huge fan of bottle.py, it's simpler/cleaner, but does lack of fucntionalities and plugin. And you'll notice that it is much higher on the the JSON serialization chart at 13% (flask and django are at 5.7% and 1.1% respectively). 1: http://bottlepy.org/ http://bottlepy.org/