Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26652

Organizing my config variable for webapp2

For simplicity I think I need to rewrite this to just one statement

config = {'webapp2_extras.jinja2': {'template_path': 'templates',
          'filters': {
          'timesince': filters.timesince,
          'datetimeformat': filters.datetimeformat},
          'environment_args': {'extensions': ['jinja2.ext.i18n']}}}

config['webapp2_extras.sessions'] = \
    {'secret_key': 'my-secret-key'}

Then I want to know where to put it if I use multiple files with multiple request handlers. Should I just put it in one file and import it to the others? Since the session code is secret, what are your recommendation for handling it via source control? To always change the secret before or after committing to source control?

Thank you

Upvotes: 2

Views: 625

Answers (2)

proppy
proppy

Reputation: 10504

I would recommend storing those in a datastore Entity for more flexibility and caching them in the instance memory at startup.

You could also consider having a config.py file excluded from the source control, if you want to get things done quickly.

Upvotes: 3

Nick Johnson
Nick Johnson

Reputation: 101139

Just add 'webapp2_extras.sessions' to your dict initializer:

config = {'webapp2_extras.jinja2': {'template_path': 'templates',
          'filters': {
          'timesince': filters.timesince,
          'datetimeformat': filters.datetimeformat},
          'environment_args': {'extensions': ['jinja2.ext.i18n']}},
          'webapp2_extras.sessions': {'secret_key': 'my-secret-key'}}

This would be clearer if the nesting were explicit, though:

config = {
  'webapp2_extras.jinja2': {
    'template_path': 'templates',
    'filters': {
      'timesince': filters.timesince,
      'datetimeformat': filters.datetimeformat
    },
    'environment_args': {'extensions': ['jinja2.ext.i18n']},
  },
  'webapp2_extras.sessions': {'secret_key': 'my-secret-key'}
}

Upvotes: 6

Related Questions