views:

137

answers:

1

I've been using Django and Django passes in a request object to a view when it's run. It looks like (from first glance) in Flask the application owns the request and it's imported (as if it was a static resource). I don't understand this and I'm just trying to wrap my brain around WSGI and Flask, etc. Any help is appreciated.

+3  A: 

In Flask request is a thread-safe global, so you actually do import it:

from flask import request

I'm not sure this feature is related to WSGI as other WSGI micro-frameworks do pass request as a view function argument. "Global" request object is a feature of Flask. Flask also encourages to store user's data which is valid for a single request in a similar object called flask.g:

To share data that is valid for one request only from one function to another, a global variable is not good enough because it would break in threaded environments. Flask provides you with a special object that ensures it is only valid for the active request and that will return different values for each request. In a nutshell: it does the right thing, like it does for request and session.

Sergey
@Sergey - YES! I'm loving this framework. Each time I stumble into a new project out there I'm soon let down by it's inefficiencies or weird ways of doing things. Flask is excellent, as is Armin for creating it. And, thanks for your answer.
orokusaki