On 23 Jul 2012, at 12:53 AM, lyn2py wrote:
> I have the code working on Localhost, but along with localhost there are the 
> response toolbar, the link to the admin site and the database used.
> 
> What code should I use to "test" if the code is being executed on the 
> production server, so that I can "hide" or switch to use a different database?
> 
> I'm deploying on Amazon EC2, if this is any helpful. Thanks!
> 
> 

One possibility: look at platform.node() or request.env.http_host or 
request.env.remote_addr in local_hosts.

Another: platform.system(). 

And a warning: I started out using request.is_local to, among other things, use 
sqlite instead of mysql. Its logic:

request.env.http_host.split(':',1)[0]
local_hosts = [http_host,'::1','127.0.0.1','::ffff:127.0.0.1']
request.is_local = request.env.remote_addr in local_hosts

But. I was running on a managed Rackspace server, and there was a server 
monitoring process that made requests locally. Until I figured that out, it was 
*really* confusing.

This stuff become (necessarily?) a little ad hoc. 

One other note, something you might want to anticipate from the beginning. I 
distinguish between three levels of server. My localhost environment runs 
Rocket and sqlite. My production server runs Apache and MySQL. My production 
test server is configured identically to the production server. It's where I 
initially deploy all my changes to make sure that migrations perform correctly, 
and that anything that might be dependent on the specific configuration works 
right. For that, I depend on the host name (above) when I need to make a 
distinction.

I end up creating two flags: is_production and use_sqlite. 

You may of course require something different.

-- 



Reply via email to