
Advanced Flask Patterns - kracekumar
https://speakerdeck.com/u/mitsuhiko/p/advanced-flask-patterns
======
j4mie
I love Flask for simple stuff, but I'm a little concerned that, as someone who
considers himself a relatively advanced Python developer, I don't really
understand quite a lot of this.

I have no doubt that if I dug into it then it would all make sense, but my
first instinct is this: how much of this complexity (proxy objects to thread
locals, context stacks etc) results from the fact that doing:

    
    
        from flask import request
    

is just a bad idea?

Perhaps things would be easier if instead of:

    
    
        from flask import request
    
        ...
    
        @app.route('/'):
        def index():
            return "Hello from %s" % request.args.get('name')
    

we did:

    
    
        @app.route('/'):
        def index(request):
            return "Hello from %s" % request.args.get('name')
    

I'm probably massively over-simplifying things, but the idea of magically
importing state is the one aspect of Flask that always felt a bit odd to me.

~~~
ch0wn
Thread locals are addressed in the docs:

    
    
        Yes it is usually not such a bright idea to use thread locals. They cause
        troubles for servers that are not based on the concept of threads and make
        large applications harder to maintain. However Flask is just not designed
        for large applications or asynchronous servers. Flask wants to make it quick
        and easy to write a traditional web application.
    
    

<http://flask.pocoo.org/docs/design/#thread-locals>

~~~
brown9-2
I haven't used Flask for a large application, but I'm curious why it would be
bad for a large application - are there not enough features built in?

What would Python developers prefer to use for a large application - Django?

~~~
chasingtheflow
Or perhaps Pyramid <http://www.pylonsproject.org/>

------
Smerity
If you're interested in this talk, Armin provides the slides and links to
video for many of his previous presentations at his website[1]. The talks
range from horrific (but useful) Python hackery to an overview of Python web
app development.

[1]: <http://lucumr.pocoo.org/talks/>

~~~
yolesaber
Thank you so much for these. His Flask talks are very intriguing and a good
yardstick for measuring your python-fu. The overview of pastebin was
enlightening.

------
Grepsy
This presentation, but with notes by Armin:

<http://dev.pocoo.org/~mitsuhiko/FlaskPatterns_notes.pdf>

------
obeattie
The video is also on YouTube
[http://www.youtube.com/watch?v=KOvgfbBFZxk&feature=youtu...](http://www.youtube.com/watch?v=KOvgfbBFZxk&feature=youtube_gdata_player)

Would definitely recommend… I was at the talk yesterday, very clever stuff.

~~~
kennywinker
This is what I want. I can never get the whole story from just the slide deck.
Need the talking too!

------
ericingram
As someone who hasn't used Flask before, this makes me not want to try. I'm
not even sure what problem is being solved in this presentation.

Anyone care to explain what these advanced patterns are useful for?

~~~
the_mitsuhiko
> Anyone care to explain what these advanced patterns are useful for?

It's not intended to be used by newcomers. It's for people that write Flask
extensions that should work in a wide range of environments. The word
“advanced” is in there for a good reason.

~~~
ericingram
Ahh that makes sense. Maybe it would have been better titled "Advanced
patterns for Flask extension developers".

~~~
obeattie
It was indeed labelled as an "advanced talk" at EuroPython (I was at it
yesterday).

------
maybe_someday
The video for this would be nice, it's a bit hard understanding some of the
slides without context.

------
earnubs
Very disappointed this wasn't a gallery of Thermos tartans.

------
yashchandra
Always happy to see Flask related stuff on HN front page :). Being a novice
python wannabe, I am still struggling with thread locals but more than happy
to keep working with Flask. Reading the source code is fun.

