
Flask vs. Django: Worksheet to choose the right framework - welder
https://wakatime.com/blog/25-pirates-use-flask-the-navy-uses-django?
======
mpdehaan2
One 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
[http://python-eve.org/](http://python-eve.org/)

~~~
mjfisher
For 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
I'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
You could also use a Django Form to validate the data with Tastypie[1].

[1] - [https://django-
tastypie.readthedocs.org/en/latest/validation...](https://django-
tastypie.readthedocs.org/en/latest/validation.html#formvalidation)

------
andybak
I 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
Interesting, 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
Yup. 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.

~~~
dev360
Interesting. Almost every experienced Django dev I know throws out the admin
on their projects nowadays.

~~~
hackerboos
In favour of what?

------
waterside81
For 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
Django/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
100% agree, but since they're so ubiquitous, I'm sure quite a few people out
there do so without thinking twice.

~~~
catshirt
you'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...

------
mixmastamyk
This 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.

~~~
testguy34
Those numbers are meaningless without knowing what the code is doing.

~~~
lucasmullens
It says on the site, but it's basically just a "hello world" json response, so
its just comparing the overhead for each web request.

------
ryannevius
The 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')

------
chdir
> 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.

------
andybak
This 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
It'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...)

------
dalke
> 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?

~~~
tosh
[http://www.folklore.org/StoryView.py?story=Pirate_Flag.txt](http://www.folklore.org/StoryView.py?story=Pirate_Flag.txt)

~~~
dalke
Ahh! 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
Part of the problem with comparing commits is the Django is more
comprehensive. There is a larger "surface area" to make changes to.

~~~
dalke
The 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.

------
freework
I'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
How do you manage with just one primary key column allowed by the ORM?

~~~
andybak
Some 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'.

------
dorfsmay
I 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/)

------
Spiritus
Perhaps a bit off topic, but what's the reason Flask hasn't had a release in
almost 2 years?

~~~
cranklin
Probably because most of the commonly used components are maintained
separately.

~~~
Spiritus
Sure, but there's been almost 700 commits. There must be something in there
worth a release.

------
nyddle
What about Python 3 adoption? Django feels a much safer bet in this regard.

------
Walkman
"It's a tie! Read about Django vs Flask to make your own choice."

Thanks, this really helps a lot! LOL

------
aprdm
What about Pyramid?

~~~
ianamartin
Personally, 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.

------
therealdrag0
I can't access the site. Is it down? Blocked?

Anyone have a mirror?

~~~
welder
Alternative url:

[https://github.com/wakatime/wakatime-
blog/blob/master/posts/...](https://github.com/wakatime/wakatime-
blog/blob/master/posts/25-pirates-use-flask-the-navy-uses-django.md)

The page loads for me just fine.

