Re: [flask] App Config Keys question
- From:
- Tomas Zulberti
- Date:
- 2011-06-28 @ 17:54
On Tue, Jun 28, 2011 at 2:36 PM, Ron DuPlain <ron.duplain@gmail.com> wrote:
> Hi Tomas,
>
> On Mon, Jun 27, 2011 at 9:15 PM, Tomas Zulberti <tzulberti@gmail.com> wrote:
>> Hi. I am working on a new Flask Extension which will use Configglue
>> [0]. This will allow to change the configuration values
>> from an INI file instead of a "settings.py" file.
>>
>> On some extensions app.config.setdefaultvalue is used, while in some
>> other it doesn't. When using the first one, I kwow which config values
>> the application has,
>> but on the second case, the only place where the config values are is
>> the documentation (or the code when getting that config value ;).
>>
>> So the question is if there is some way to know the configuration keys
>> for any Flask extension getting the values from the "app" or from
>> somewhere else.
>
> Being a dict, you can access all config keys on the app like this:
>
> app.config.keys()
>
> But in your INI case, I take it you'd like to group configuration into
> sections, where sections map to extensions. Currently, there are no
> conventions for grouping/namespacing/prefixing config keywords with
> the extension.
>
> Perhaps you could use sections in the INI as an annotation, and
> flatten out the sections when loading into app.config. With this
> approach, a [SQLAlchemy] (or [Flask-SQLAlchemy]?) section would
> provide a sensible grouping of Flask-SQLAlchemy config values, even
> though the section name isn't used.
>
> Would this approach work for you extension?
>
> Ron
The problem is that with that approach, is that some applications
doesn't set the config keys to the app.config. For example,
SQLAlchemy will use app.config.setdefault. This allows me to get all
the required keys.
But, Flask-Mail doesn't use app.config.setdefault, and only reads the
config values. So there is no way for mi application to get
the config keys required by that application.
Nevertheless, I changed mi approach.
Thanks,
Tomas Zulberti