Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web2py with configuration per environment

Tags:

python

web2py

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.

like image 271
jarekrozanski Avatar asked Jan 23 '26 03:01

jarekrozanski


1 Answers

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.

like image 86
Massimo Avatar answered Jan 24 '26 19:01

Massimo