Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Document use of VCAP_SERVICES in django's settings.py
Browse files Browse the repository at this point in the history
(also removed the sample app, as it lives in the tests repo)

Change-Id: I5cdf9995584f20c4df38877840c400899e86a451
  • Loading branch information
Sridhar Ratnakumar authored and Patrick Bozeman committed Aug 12, 2011
1 parent 28a6a46 commit 25e9619
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions docs/python.md
Expand Up @@ -23,6 +23,41 @@ A special framework called "Django" exists to also perform Django-specific
staging actions. At the moment, this runs `syncdb` non-interactively to
initialize the database.

### Accessing the database

Cloud Foundry makes the service connection credentials available as JSON via the
`VCAP_SERVICES` environment variable. Using this knowledge, you can use the
following snippet in your own settings.py:

## Pull in CloudFoundry's production settings
if 'VCAP_SERVICES' in os.environ:
import json
vcap_services = json.loads(os.environ['VCAP_SERVICES'])
# XXX: avoid hardcoding here
mysql_srv = vcap_services['mysql-5.1'][0]
cred = mysql_srv['credentials']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': cred['name'],
'USER': cred['user'],
'PASSWORD': cred['password'],
'HOST': cred['hostname'],
'PORT': cred['port'],
}
}
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "dev.db",
"USER": "",
"PASSWORD": "",
"HOST": "",
"PORT": "",
}
}

### Limitations

* Django admin (if your app uses it) will be unusable as superusers are not
Expand All @@ -31,28 +66,3 @@ initialize the database.
* Migration workflow, such as that of [South](http://south.aeracode.org/) are
not supported.

## Sample applications

### A hello world WSGI application

Here's a sample WSGI application using the "bottle" web framework.

$ mkdir myapp && cd myapp
$ cat > wsgi.py
import os
import sys
import bottle

@bottle.route('/')
def index():
pyver = '.'.join(map(str, tuple(sys.version_info)[:3]))
return 'Hello World! (from <b>Python %s</b>)' % (pyver,)

application = bottle.default_app()

if __name__ == '__main__':
bottle.run(host='localhost', port=8000)

$ cat > requirements.txt
bottle
$

0 comments on commit 25e9619

Please sign in to comment.