Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask for Python - architectural question regarding the system

Tags:

python

flask

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.

like image 969
orokusaki Avatar asked Sep 19 '10 18:09

orokusaki


1 Answers

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.

like image 82
Sergey Avatar answered Oct 10 '22 16:10

Sergey