3

Does web2py support, out of the box, configuration per environment (development, staging, production, etc.)? Something similar to Grails and Ruby on Rails.

I read/skimmed through official book but could not find anything.

Jarek Rozanski
  • 780
  • 1
  • 6
  • 13

1 Answers1

4

The web2py developers do not believe that is a good approach.

We do not believe in the sharp distinction between development and production. For eaxmple, if an app has a bug, the bug is always recorded and logged, never shown to the user, only shown to the administrator.

Moreover web2py does not have a configuration file at all because apps should be portable without mangling with settings.

Yet you can manage different environments and in a more sophisticated way than Rails or Django allows. That is because models are not imported but executed at every request. You add your own conditions to detect the environment at runtime. For example:

  settings = dict()
  if request.env.http_host == 'http://127.0.0.1:8000'
       settings['development']=True
  else:
       settings['development']=False
  if settings['development']:
       db = DAL('sqlite://....')
  else:
       db = DAL('mysql://....')

You can see how to generalize this to more complex conditions. Of course you can make settings['development']=True or False constant, which is the Rails equivalent way of doing it.

Massimo
  • 1,653
  • 12
  • 11
  • Ok, so that's the way I've been doing it so far. Reminds me of my long past PHP times. I still prefer clear environment distiction but since this is web2py way, so be it. – Jarek Rozanski May 31 '11 at 10:22