Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 339
Niklas Rosencrantz Avatar asked Mar 01 '26 18:03

Niklas Rosencrantz


1 Answers

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'}
}
like image 120
Nick Johnson Avatar answered Mar 03 '26 08:03

Nick Johnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!