views:

155

answers:

2

Whilst developing I want to handle some things slight differently than I will when I eventually upload to the Google servers.

Is there a quick test that I can do to find out if I'm in the SDK or live?

+2  A: 

See: http://code.google.com/appengine/docs/python/runtime.html#The_Environment

The following environment variables are part of the CGI standard, with special behavior in App Engine: SERVER_SOFTWARE:

In the development web server, this value is "Development/X.Y" where "X.Y" is the version of the runtime.

When running on App Engine, this value is "Google App Engine/X.Y.Z".

The MYYN
Thanks something like this works for me now:import osdef development(): if os.environ['SERVER_SOFTWARE'].find('Development') == 0: return True else: return False
It's eaten my formatting in the comment, but you know what I mean. Cheers
Simpler: os.environ['SERVER_SOFTWARE'].startswith('Development')
Dave W. Smith
A: 

Based on the same trick, I use this function in my code:

def isLocal():
    return os.environ["SERVER_NAME"] in ("localhost", "www.lexample.com")

I have customized my /etc/hosts file in order to be able to access the local version by prepending a "l" to my domain name, that way it is really easy to pass from local to production.

Example:

  • production url is www.example.com
  • development url is www.lexample.com
Emilien