Integration

Gunicorn also provides integration for Django and Paste Deploy applications.

Django

Gunicorn will look for a WSGI callable named application if not specified. So for a typical Django project, invoking Gunicorn would look like:

  1. $ gunicorn myproject.wsgi

Note

This requires that your project be on the Python path; the simplest way to ensure that is to run this command from the same directory as your manage.py file.

You can use the –env option to set the path to load the settings. In case you need it you can also add your application path to PYTHONPATH using the –pythonpath option:

  1. $ gunicorn --env DJANGO_SETTINGS_MODULE=myproject.settings myproject.wsgi

Paste Deployment

Frameworks such as Pyramid and Turbogears are typically configured using Paste Deployment configuration files. If you would like to use these files with Gunicorn, there are two approaches.

As a server runner, Gunicorn can serve your application using the commands from your framework, such as pserve or gearbox. To use Gunicorn with these commands, specify it as a server in your configuration file:

  1. [server:main]
  2. use = egg:gunicorn#main
  3. host = 127.0.0.1
  4. port = 8080
  5. workers = 3

This approach is the quickest way to get started with Gunicorn, but there are some limitations. Gunicorn will have no control over how the application is loaded, so settings such as reload will have no effect and Gunicorn will be unable to hot upgrade a running application. Using the daemon option may confuse your command line tool. Instead, use the built-in support for these features provided by that tool. For example, run pserve --reload instead of specifying reload = True in the server configuration block. For advanced configuration of Gunicorn, such as Server Hooks specifying a Gunicorn configuration file using the config key is supported.

To use the full power of Gunicorn’s reloading and hot code upgrades, use the paste option to run your application instead. When used this way, Gunicorn will use the application defined by the PasteDeploy configuration file, but Gunicorn will not use any server configuration defined in the file. Instead, configure gunicorn.

For example:

  1. $ gunicorn --paste development.ini -b :8080 --chdir /path/to/project

Or use a different application:

  1. $ gunicorn --paste development.ini#admin -b :8080 --chdir /path/to/project

With both approaches, Gunicorn will use any loggers section found in Paste Deployment configuration file, unless instructed otherwise by specifying additional logging settings.