librelist archives

« back to archive

Contexts

Contexts

From:
Anant Rao
Date:
2014-05-14 @ 02:19
Hi,

I recently started working with Flask. I find it an amazing piece of
software. One thing that's confusing is the concept of contexts. I read
thru the doc and I find them confusing.

I went thru the impl code as well for the app, Local etc. I see that
thread-local storage is used for them. That's all I could figure out. The
scope of the 'app' object is not clear.

I know we can do something like
g.foo = 10

This variable and its value remain valid for the duration of the request.

I could do this as well:
app.foo = 10

However, I'm not sure if this is ok to do and what the scope/lifetime of
this variable is.

Thanks in advance!

Re: [flask] Contexts

From:
Shalabh Aggarwal
Date:
2014-05-14 @ 03:53
It actually depends on what you are aiming to do.

Flask.g object is basically used for user specific code.

Flask.app object is preferable used for storing configuration information
at the top level.

Furthermore, this piece of doc should help you more in understanding. [
http://flask.pocoo.org/docs/appcontext/#locality-of-the-context ]


On Wed, May 14, 2014 at 7:49 AM, Anant Rao <arao@noknok.com> wrote:

> Hi,
>
> I recently started working with Flask. I find it an amazing piece of
> software. One thing that's confusing is the concept of contexts. I read
> thru the doc and I find them confusing.
>
> I went thru the impl code as well for the app, Local etc. I see that
> thread-local storage is used for them. That's all I could figure out. The
> scope of the 'app' object is not clear.
>
> I know we can do something like
> g.foo = 10
>
> This variable and its value remain valid for the duration of the request.
>
> I could do this as well:
> app.foo = 10
>
> However, I'm not sure if this is ok to do and what the scope/lifetime of
> this variable is.
>
> Thanks in advance!
>
>

Re: [flask] Contexts

From:
Vadim Statishin
Date:
2014-05-14 @ 07:29
On the use of context in the application, you can view a video report Armin
Ronacher on EuroPython -
https://ep2013.europython.eu/conference/talks/advanced-flask-patterns


2014-05-14 6:53 GMT+03:00 Shalabh Aggarwal <contact@shalabhaggarwal.com>:

> It actually depends on what you are aiming to do.
>
> Flask.g object is basically used for user specific code.
>
> Flask.app object is preferable used for storing configuration information
> at the top level.
>
> Furthermore, this piece of doc should help you more in understanding. [
> http://flask.pocoo.org/docs/appcontext/#locality-of-the-context ]
>
>
> On Wed, May 14, 2014 at 7:49 AM, Anant Rao <arao@noknok.com> wrote:
>
>> Hi,
>>
>> I recently started working with Flask. I find it an amazing piece of
>> software. One thing that's confusing is the concept of contexts. I read
>> thru the doc and I find them confusing.
>>
>> I went thru the impl code as well for the app, Local etc. I see that
>> thread-local storage is used for them. That's all I could figure out. The
>> scope of the 'app' object is not clear.
>>
>>  I know we can do something like
>> g.foo = 10
>>
>> This variable and its value remain valid for the duration of the request.
>>
>> I could do this as well:
>> app.foo = 10
>>
>> However, I'm not sure if this is ok to do and what the scope/lifetime of
>> this variable is.
>>
>> Thanks in advance!
>>
>>
>


-- 
Vadim