views:

443

answers:

2

How do you setup a settings file? One is for your local development server and another set of setting values for when you upload to Google App Engine?

For example, I would like to set up a settings file where I store the Absolute Root URL.

+4  A: 

It's not clear from your question if you're asking about the Java or Python runtime. I'll assume Python for now.

Just like any other Python webapp, the settings file can be wherever and whatever you want. I usually use a .py file called 'settings.py' or 'config.py' in the root directory of my app. For example, see Bloog's settings file.

As far as having different settings for production and development goes, you have two options:

  1. Simply keep two branches in your source code repository, one for dev and one for prod, and periodically merge from dev to prod when you want to do a release. In this case, you just don't merge config.py.
  2. Autodetect which platform you're running on, and apply settings as appropriate. The easiest way to do this is to check the value of os.environ['SERVER_SOFTWARE'], which will start with 'Dev' if it's the development server. You can use this to set a flag like so:

    DEBUG = os.environ['SERVER_SOFTWARE'].startswith('Dev')

Nick Johnson
+1  A: 

You can find out the root URL from the request, and use that instead of configuring it manually. Or if you need further configuration, then use that to decide which config to use.

Kevin Reid