gunicorn.txt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ===============================
  2. How to use Django with Gunicorn
  3. ===============================
  4. .. highlight:: bash
  5. Gunicorn_ ('Green Unicorn') is a pure-Python WSGI server for UNIX. It has no
  6. dependencies and is easy to install and use.
  7. .. _Gunicorn: http://gunicorn.org/
  8. There are two ways to use Gunicorn with Django. One is to have Gunicorn treat
  9. Django as just another WSGI application. The second is to use Gunicorn's
  10. special `integration with Django`_.
  11. .. _integration with Django: http://gunicorn.org/run.html#django-manage-py
  12. Installing Gunicorn
  13. ===================
  14. Installing gunicorn is as easy as ``sudo pip install gunicorn``. For more
  15. details, see the `gunicorn documentation`_.
  16. .. _gunicorn documentation: http://gunicorn.org/install.html
  17. Running Django in Gunicorn as a generic WSGI application
  18. ========================================================
  19. When Gunicorn is installed, a ``gunicorn`` command is available which starts
  20. the Gunicorn server process. At its simplest, gunicorn just needs to be called
  21. with a the location of a WSGI application object.::
  22. gunicorn [OPTIONS] APP_MODULE
  23. Where ``APP_MODULE`` is of the pattern ``MODULE_NAME:VARIABLE_NAME``. The
  24. module name should be a full dotted path. The variable name refers to a WSGI
  25. callable that should be found in the specified module.
  26. So for a typical Django project, invoking gunicorn would look like::
  27. gunicorn myproject.wsgi:application
  28. (This requires that your project be on the Python path; the simplest way to
  29. ensure that is to run this command from the same directory as your
  30. ``manage.py`` file.)
  31. Using Gunicorn's Django integration
  32. ===================================
  33. To use Gunicorn's built-in Django integration, first add ``"gunicorn"`` to
  34. :setting:`INSTALLED_APPS`. Then run ``python manage.py run_gunicorn``.
  35. This provides a few Django-specific niceties:
  36. * sets the gunicorn process name to be that of the project
  37. * validates installed models
  38. * allows an ``--adminmedia`` option for passing in the location of the
  39. admin media files.
  40. See Gunicorn's `deployment documentation`_ for additional tips on starting and
  41. maintaining the Gunicorn server.
  42. .. _deployment documentation: http://gunicorn.org/deploy.html