News for hackers. Stuff that matters.
Re:Django vs. Flask by orf on Tuesday July 04, 2017 @04:57AM (#14694537)
I was interested so I had a look at the source. There is a single use of a threading.local object in the RegexResolver.

There are 5 other usages in total, one in the live reloader, two in the tests and two in GeoDjango.

Explicit magic is still magic, and Django contains surprisingly little magic of any type overall, including thread locals.

Re:Django vs. Flask by Walkman on Tuesday July 04, 2017 @05:35PM (#14698453)
Re:Django vs. Flask by orf on Tuesday July 04, 2017 @05:51PM (#14698538)
Good point, I was only searching for explicit "threading.local" references. So there are 4 more or so.

Django uses thread locals in some places where it's needed, but that's beside the point though. It doesn't put thread local objects at the core of its API. Passing an explicit request (real or fake) into functions is much more testable and generally better than relying on a 'request' global, IMO. Same with all the other app globals [1].

A better, more specific argument about Django's use of magic is the models. It uses some dark black magic voodo metaclasses to implement those. Apart from that, the forms, admin, app registry, urls, views is pretty straightforward.

But hey, it's personal preference. I like flask mostly: for some situations it is amazing.

1. http://flask.pocoo.org/docs/0.12/api/#application-globals

Re:Django vs. Flask by Walkman on Thursday July 06, 2017 @04:42PM (#14713783)
About testing: it's not actually True. Flask is easy to test. Also, Flask makes everything explicit which is less surprising than hidden thread locals.

Also, putting things into thread locals somewhere makes explicit request objects totally pointless, because you still depend on threads and can't use Django in an async manner. So it's not a valid good technical argument either. You might like that better, but that's just a subjective opinion.