How to use Django with uWSGI

    See also

    The uWSGI docs offer a tutorial covering Django, nginx, and uWSGI (one possible deployment setup of many). The docs below are focused on how to integrate Django with uWSGI.

    The uWSGI wiki describes several . Using pip, the Python package manager, you can install any uWSGI version with a single command. For example:

    uWSGI operates on a client-server model. Your web server (e.g., nginx, Apache) communicates with a “worker” process to serve dynamic content.

    Configuring and starting the uWSGI server for Django

    Here’s an example command to start a uWSGI server:

    This assumes you have a top-level project package named mysite, and within it a module mysite/wsgi.py that contains a WSGI application object. This is the layout you’ll have if you ran django-admin startproject mysite (using your own project name in place of ) with a recent version of Django. If this file doesn’t exist, you’ll need to create it. See the documentation for the default contents you should put in this file and what else you can add to it.

    The Django-specific options here are:

    • module: The WSGI module to use – probably the mysite.wsgi module that startproject creates.
    • home: Optional path to your project virtual environment.

    Example ini configuration file:

    Fixing UnicodeEncodeError for file uploads

    If you get a UnicodeEncodeError when uploading files with file names that contain non-ASCII characters, make sure uWSGI is configured to accept non-ASCII file names by adding this to your uwsgi.ini:

    See the section of the Unicode reference guide for details.

    See the uWSGI docs on managing the uWSGI process for information on starting, stopping and reloading the uWSGI workers.