开发者

Flask for Python - architectural question regarding the system

开发者 https://www.devze.com 2023-01-16 23:02 出处:网络
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 s

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 ap开发者_运维百科preciated.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消