This site has moved, this is just for reference, please visit the current one.

P Bergqvist

Using environment variables on Gondor

Published: maj 19, 2012

Tags: django gondor

Comments:  

A trouble when using git/hg-based push to application servers is that everything has to be in the repo. So no more production_settings.py etc on the production server. This is easly solved by using the environment and let it provide the variables to us.

On Gondor this is currently undocumented but you can always dig through the (source)[https://github.com/eldarion/gondor-client/blob/master/gondor/main.py] for the client to figure it out;-)

So a quick chat in the #gondor channel at Freenode helped me with this.

 gondor env

Lists all the current environment variables

 gondor env:set 'KEY'='VALUE'

To set a environment variable, it's important that no whitespaces gets in there between the equal sign and the 'KEY' and 'VALUE'.

To use this in your code it's just to do something like:

 import os
 thing = os.getenv('KEY')
 # or
 thing = os.environ['KEY']

Remember that the second way will crash if that environment is not available, so a try-except would be good to use.

blog comments powered by Disqus

Copyright © 2012 Me. All rights reserved.