Skip to main content

Buildout recipe for Django

Project description

Djangorecipe: easy install of Django with buildout


This buildout recipe can be used to create a setup for Django. It will automatically download Django and install it in the buildout’s sandbox.

You can see an example of how to use the recipe below:

parts = satchmo django
eggs =
versions = versions

Django = 1.5.5

recipe =
url =
md5sum = 659a4845c1c731be5cfe29bfcc5d14b1

recipe = djangorecipe
settings = development
eggs = ${buildout:eggs}
extra-paths =
project = dummyshop

Supported options

The recipe supports the following options.

This option sets the name for your project. The recipe will create a basic structure if the project is not already there.
Use this instead of the project option when you want to use an egg as the project. This disables the generation of the project structure.
You can set the name of the settings file which is to be used with this option. This is useful if you want to have a different production setup from your development setup. It defaults to development.
All paths specified here will be used to extend the default Python path for the bin/* scripts.
Adds paths found from a site .pth file to the extra-paths. Useful for things like Pinax which maintains its own external_libs dir.
The name of the script created in the bin folder. This script is the equivalent of the Django normally creates. By default it uses the name of the section (the part between the [ ]).
Specify some Python initialization code to be inserted into the control-script. This is very limited. In particular, be aware that leading whitespace is stripped from the code given.
An extra script is generated in the bin folder when this is set to true. This can be used with mod_wsgi to deploy the project. The name of the script is control-script.wsgi.
The name of the wsgi-script that is generated. This can be useful for gunicorn.
In case the WSGI server you’re using does not allow printing to stdout, you can set this variable to a filesystem path - all stdout/stderr data is redirected to the log instead of printed
If you want a script in the bin folder to run all the tests for a specific set of apps this is the option you would use. Set this to the list of app labels which you want to be tested.
This is the name of the testrunner which will be created. It defaults to test.

All following options only have effect when the project specified by the project option has not been created already.

You can set this to a specific url conf. It will use project.urls by default.
The secret to use for the, it generates a random string by default.

Another example

The next example shows you how to use some more of the options:

parts = django extras
eggs =

recipe = iw.recipe.subversion
urls = django-command-extensions django-mptt

recipe = djangorecipe
settings = development
project = exampleproject
wsgi = true
eggs =
test =

Example using .pth files

Pinax uses a .pth file to add a bunch of libraries to its path; we can specify it’s directory to get the libraries it specified added to our path:

parts = PIL

django        = 1.3

recipe        = zc.recipe.egg:custom
egg           = PIL
find-links    =

recipe        = iw.recipe.subversion
urls          =       pinax

recipe        = djangorecipe
eggs          =
project       = myproject
settings      = settings
extra-paths   = ${buildout:directory}/myproject/apps
pth-files     = ${svncode:location}/pinax/libs/external_libs
wsgi          = true

Above, we use stock Pinax for pth-files and extra-paths paths for apps, and our own project for the path that will be found first in the list. Note that we expect our project to be checked out (e.g., by svn:external) directly under this directory in to ‘myproject’.

Example with a Django version from a repository

If you want to use a specific Django version from a source repository you could use mr.developer: Here is an example for using the Django development version:

parts = django
extensions = mr.developer
auto-checkout = *

django = git

recipe = djangorecipe
settings = settings
project = project

Example configuration for mod_wsgi

If you want to deploy a project using mod_wsgi you could use this example as a starting point:

<Directory /path/to/buildout>
       Order deny,allow
       Allow from all
       ServerName      my.rocking.server
       CustomLog       /var/log/apache2/my.rocking.server/access.log combined
       ErrorLog        /var/log/apache2/my.rocking.server/error.log
       WSGIScriptAlias / /path/to/buildout/bin/django.wsgi

Generating a control script for PyDev

Running Django with auto-reload in PyDev requires adding a small snippet of code:

import pydevd
pydevd.patch_django_autoreload(patch_remote_debugger=False, patch_show_console=True)

just before the if __name__ == “__main__”: in the module (or in this case the control script that is generated). This example buildout generates two control scripts: one for command-line usage and one for PyDev, with the required snippet, using the recipe’s initialization option:

parts = django pydev
eggs =

recipe = djangorecipe
eggs = ${buildout:eggs}
project = dummyshop

<= django
initialization =
  import pydevd
  pydevd.patch_django_autoreload(patch_remote_debugger=False, patch_show_console=True)

Several wsgi scripts for one Apache virtual host instance

There is a problem when several wsgi scripts are combined in a single virtual host instance of Apache. This is due to the fact that Django uses the environment variable DJANGO_SETTINGS_MODULE. This variable gets set once when the first wsgi script loads. The rest of the wsgi scripts will fail, because they need a different settings modules. However the environment variable DJANGO_SETTINGS_MODULE is only set once. The new initialization option that has been added to djangorecipe can be used to remedy this problem as shown below:

settings = acceptance
initialization =
    import os
    os.environ['DJANGO_SETTINGS_MODULE'] = '${django:project}.${django:settings}'

Example usage of django-configurations

django-configurations ( is an application that helps you organize your Django settings into classes. Using it requires modifying the file. This is done easily using the recipe’s initialization option:

parts = django
eggs =

recipe = djangorecipe
eggs = ${buildout:eggs}
project = myproject
initialization =
    # Patch the manage file for django-configurations
    import os
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
    os.environ.setdefault('DJANGO_CONFIGURATION', 'Development')
    from import execute_from_command_line
    import django = execute_from_command_line


1.7 (2013-12-11)

  • Add option to change the wsgi script name. Thanks hedleyroos (Fixes pull #74)

1.6 (2013-10-28)

  • Djangorecipe works with django 1.6 now.
  • Tested with Django 1.4, 1.5 and 1.6. Pre-1.4 support is gone, now. Also tested on Python 2.6/2.7, 3.2/3.3.
  • Moved to buildout 2 support only.
  • Removed generation of fastcgi script. You can run it easily as bin/django runfcgi and it will be deprecated in Django 1.7 anyway.

1.5 (2013-01-25)

  • Removed support for a different python version than the one you use to run buildout with. Previously, you could run your buildout with 2.6 but get Django to use 2.7 instead. zc.buildout 2.0 doesn’t allow it anymore, so we removed it too.

1.4 (2013-01-15)

  • Added initialization code support. Thanks to anshumanb, jjmurre. (Closes #58).

1.3 (2012-09-07)

  • Removed deprecation warning in Django 1.4. Fixes #49, thanks Shagi.
  • Added documentation for use with mr.developer. Thanks shagi (closes issue #45)
  • Added Travis support.

1.2.1 (2012-05-15)

  • Fixed broken 1.2 release (missing *.rst files due to a recent txt-to-rst rename action).

1.2 (2012-05-14)

  • Removed location path from recipe. Thanks bleskes (fixes issue #50).


  • Added correct url to the deprecation warning


  • Fixed Python3 Trove classifiers


  • Support python3.
  • Changed buildout and the tests to run the tests under nose.
  • Removed some old pre 0.99 unittests that dealt with download support.


  • Stable release with a real 1.0 version.
  • Made djangorecipe more pep08 compliant.


  • Djangorecipe now depends on Django. The use of the version = statement is deprecated. Specify the django version in the [versions] section. Install django via mr.developer if you need to use an svn/git/hg repository. For other uses Versionpin djangorecipe to 0.23.1 if you don’t want to upgrade. Thanks to Reinout van Rees for help with this release.
  • Removed subversion and download support.


  • Added a missing ‘import os’


  • Support for settings/urls boilerplate for django 1.2 and django 1.3. It defaults to 1.3 when the version isn’t 1.2.


  • Added support for svn urls with spaces. Thanks to Brad103 (fixes #537718).
  • Updated code and buildout to use newest zc.recipe.egg, zc.recipe.testrunner and python-dateutil.


  • The admin url is now configured for django 1.1 or higher. Thanks to Sam Charrington (fixes #672220).
  • updated (fixes #501954).


  • The recipe know makes the django package know to setuptools during install. This closes #397864. Thanks to Daniel Bruce and Dan Fairs for the patch.
  • Fixed #451065 which fixes a problem with the WSGI log file option.
  • Added the posibilty to configure more FCGI related settings. Thanks to Vasily Sulatskov for the patch.


  • The generated WSGI & FCGI scripts are now properly removed when options change (fixes #328182). Thanks to Horst Gutmann for the patch.
  • Scripts are now updated when dependencies change. This fixes #44658, thanks to Paul Carduner for the patch.


  • Applied fix for the change in WSGI script generation. The previous release did not work properly.


  • When running again with non-newest set the recipe will no longer update the Subversion checkout. Thanks to vinilios for the patch.
  • The WSGI and FCGI scripts are now generated using Buildout’s own system. This makes them more similar to the generated manage script with regard to the setup of paths. Thanks to Jannis Leidel for the patch.


  • Paths from eggs and extra-paths now get precedence over the default system path (fixes #370420). Thanks to Horst Gutmann for the patch.
  • The generated WSGI script now uses the python option if present. This fixes #361695.


  • Fixed a problem when not running in verbose mode (fixes #375151).


  • Removed dependency on setuptools_bzr since it does not seem to work like I expected.


  • Changed the download code to use urllib2. This should make it work from behind proxies (fixes #362822). Thanks to pauld for the patch.


  • Fixed a problem with the new WSGI logging option #348797. Thanks to Bertrand Mathieu for the patch.
  • Disable generation of the WSGI log if “wsgilog” isn’t set, thanks to Jacob Kaplan-Moss for the patch.
  • Updated buildout.cfg and .bzrignore, thanks Jacob Kaplan-Moss.


  • Added an option to specify a log file for output redirection from the WSGI script. Thanks to Guido Wesdorp for the patch.


  • Subversion aliases are now supported (something like svn+mystuff://myjunk). Thanks to Remco for the patch.


  • Update to move pth-files finder from the __init__ method to the install method so it runs in buildout-order, else it looks for pth files in dirs that may not yet exist. Thanks to Chris Shenton for the update to his original patch.


  • Update to make the previously added pth-files option better documented.


  • Added “pth-files” option to add libraries to extra-paths from site .pth files. Thanks to Chris Shenton for the patch.


  • The recipe now supports creating a FCGI script. Thanks to Jannis Leidel for the patch.
  • When downloading a Django recipe for the first time the recipe now properly reports the url it is downloading from.


  • Specifying a user name within a subversion url now works. The code that determined the revision has been updated. This fixes issue #274004. Thanks to Remco for the patch.
  • Updated the template for creating new projects. It now uses the current admin system when generating it’s file. This fixes issue #276255. Thanks to Roland for the patch.


  • Re-upload since CHANGES.txt was missing from the release


  • The recipe no longer executes subversion to determine whether the versions is to be downloaded using subversion. This fixes issue #271145. Thanks to Kapil Thangavelu for the patch.
  • Changed the pythonpath option to extra-paths. This makes the recipe more consistent with other recipes (see issue #270908).


  • Another go at fixing the updating problem (#250811) by making sure the update method is always called. It would not be called in the previous version since the recipe wrote a random secret (if it wasn’t specified) to the options for use with a template. Buildout saw this as a change in options and therefore always decided to un-install & install.
  • When both projectegg and wsgi=True are specified, the generated wsgi file did not have the correct settings file in it. This has been fixed with a patch from Dan Fairs.
  • The recipe now has logging. All print statements have been replaced and a few extra logging calls have been added. This makes the recipe more informative about long running tasks. Thanks erny for the patch from issue #260628.


  • The recipe no longer expects the top level directory name in a release tarball to be consistent with the version number. This fixes issue #260097. Thanks to erny for reporting this issue and suggesting a solution.
  • Revision pinns for the svn checkout now stay pinned when re-running the buildout. This fixes issue #250811. Thanks to Remco for reporting this.
  • Added an option to specify an egg to use as the project. This disables the code which creates the basic project structure. Thanks to Dan Fairs for the patch from issue #252647.


  • Fixed the previous release which was broken due to a missing manifest file


  • The settings option is fixed so that it supports arbitrary depth settings paths (example; conf.customer.development).
  • The version argument now excepts a full svn url as well. You can use this to get a branch or fix any url to a specific revision with the standard svn @ syntax
  • The wsgi script is no longer made executable and readable only by the user who ran buildout. This avoids problems with deployment.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for djangorecipe, version 1.7
Filename, size File type Python version Upload date Hashes
Filename, size (35.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page