Why not simply do

__redis = StrictRedis(host=app.config['REDIS_SETTINGS']['hostname'])

Since your app object is available?


On 18 July 2014 14:49:23 CEST, Marce Romagnoli <[email protected]> 
wrote:
>Thanks for your reply, Markus. 
>The first g.config = app.config line was something I tested and leave
>there 
>by mistake.
>
>If I understand, you are saying that I should do something like:
>
>app = Flask(__name__)
>ctx = app.app_context()
>ctx.push()
>
>with ctx:
>            __redis = StrictRedis(host = 
>current_app.config['REDIS_SETTINGS']['hostname']) 
>
>If so, this didn't work for me. Like this, I only could retrieve
>default 
>settings object.
>
>I have to set configs again like: 
>app.config.from_object(config[config_name])
>config[config_name].init_app(app)
>
>That *config_name* var, tells me if config is for Dev or Production,
>but is 
>set at the time the app is run.
>Perhaps, I should set that value in an env var, due at this level I
>cannot 
>know what environment was set.
>
> -- Marce
>
>
>
>
>
>
>
>
>El jueves, 17 de julio de 2014 21:01:37 UTC-3, Markus Unterwaditzer 
>escribió:
>>
>> On Thu, Jul 17, 2014 at 12:27:33PM -0700, Marce Romagnoli wrote: 
>> >     from api_0_0_1.models.client import db 
>> >     db.init_app(app) 
>> > 
>> >     g.config = app.config 
>>
>> This works only during a request, i.e. not right now. 
>>
>> Not sure why you want that too. The ``g`` object is for data that
>needs to 
>> be 
>> stored for the lifetime of the request context, but you can access
>your 
>> config 
>> via ``current_app.config`` anyways at that time. 
>>
>> >     return app 
>> > 
>> > 
>> > if __name__ == '__main__': 
>> >     app = create_app('development') 
>> >     app.run() 
>> > 
>> > But I cannot read those config values from a module I use, I have
>the 
>> > error: *RuntimeError: working outside of application context. *I am
>
>> doing: 
>> > 
>> > from flask import current_app as app 
>> > from redis import StrictRedis 
>> > 
>> > 
>> > class RedisSomething(): 
>> >    __redis = StrictRedis(host = 
>> app.config['REDIS_SETTINGS']['hostname']) 
>> > 
>> > 
>> > Is there any way to access those same configs set when app is
>created? 
>>
>> Same thing here. You'd have to import the app itself instead of using
>
>> current_app. I recommend you execute all this code inside your app
>factory 
>> or 
>> after the factory is used. 
>>
>> -- Markus 
>>

-- 
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/d/optout.

Reply via email to