Running the example project

To demonstrate (and test) django-environments, it comes with an example Django project, located in the top-level example directory in the source code.

Note

When installing django-environments from PyPI, only the bare essentials are installed. To run you the example project, follow the instructions for a local development setup.

Everything below assumes you already have a local checkout from the Github repository.

To run the example project, you can use the example/bin/initenv.sh example script:

$ workon django-environments
$ source ~/Development/Projects/django-environments/example/bin/initenv.sh
$ runserver

To make it even easier, you may want to hook into virtualenvwrapper’s postactivate hook:

$ echo 'source ~/dev/django-environments/example/bin/initenv.sh' >> $WORKON_HOME/django-environments/bin/postactivate
$ workon django-environments
$ runserver

For more details on, see the contents of the example/bin/initenv.sh file.

Warning

Alternatively, instead of sourcing the example initenv.sh script from the postactivate script, you might be tempted to symlink the file. This won’t work however, as it breaks the current PROJECT_ROOT detection in the example initenv.sh script:

PROJECT_ROOT=$(cd -P "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)

Directories

  • The mysite/example/settings directory replaces settings.py and contains the default settings in generic.py, whose contents are imported in __init__.py.
  • The mysite/settings/env directory contains the different settings files for every environment.
  • All .wsgi files in the mysite/deploy folder are normally equal, except for the sys.path configuration. Their respective filenames are used to determine which settings to import. If your Apache configuration allows it, you could use symlinks instead of copies.

Remarks

Todo

Check if this information is still accurate

  • urls.py is just there to demonstrate the SERVE_MEDIA setting, which is not essential anyway.
  • manage.py was removed as the generated default ignores $DJANGO_SETTINGS_MODULE, simply importing ‘settings’ instead.
  • the Django startapp command will create new apps in $DJANGO_PROJECT/settings/env. Apparently, Django uses the basename of the settings __file__ as a reference point for the new app.