Thursday, November 12, 2009

local_settings at google app engine

A common trick done in django is have a separated file for local development settings, like:

#settings.py

try:
from localsettings import *
except ImportError:
print 'localsetting could not be imported'
pass #Or raise

An easy way to achieve this with the app egine dev_appserver is check the SERVER_SOFTWARE enviroment value, so even if the dev_settings are uploaded to the live version it doesn’t load the dev settings.
Code speaks louder than words:

#settings.py

import os
SERVER_SOFTWARE = os.getenv('SERVER_SOFTWARE', None)

if SERVER_SOFTWARE:
DEV_SERVER = SERVER_SOFTWARE.split('/')[0] == "Development"
else:
DEV_SERVER = False

if DEV_SERVER:
try:
from dev_settings import *
except ImportError:
pass

Notes

  1. sserrano posted this