1

My app uses Python with cherrypy to provide a web service. I want to set up a different config file, depending on if my application is started on my local machine or on my remote server.

Is there any easy way to check if my application is started from the server or on my local machine? If not, maybe I could pass some parameters, when running python myApp.py, which myApp.py will then be passed to myApp.py? Of course an automatic solution would be nicer.

cherrun
  • 2,102
  • 8
  • 34
  • 51

1 Answers1

2

Create a local configuration file and put a variable named environment inside it. Assign it dev for local env and production for production, and anything else you'd like. Just set it once, then reuse it everywhere -

from local_settings.py import environment
if environment == 'dev':
    debug = True
    # anything you'd like

If you're using any VCS like git, and using that to deploy, ignore the local_settings.py file. Local settings files are also handy for saving sensitive data that should not be public in any VCS repo, like API keys and all.

Bibhas Debnath
  • 14,559
  • 17
  • 68
  • 96
  • Well, but not checking in the file into the VCS would result in an ImportError, wouldn't it? – cherrun Mar 21 '13 at 10:02
  • You have to manually create the file once. Then you can use it afterwards. You can also catch ImportError and assume that it's production env. Whatever your like. – Bibhas Debnath Mar 21 '13 at 10:03