Django Apps§

To run your Django projects and apps in Unit:

  1. Install Unit with the appropriate Python language module version.

  2. If you haven’t already done so, create your Django project and apps where you usually store them.

  3. Prepare Unit configuration for your update. To obtain an initial template, query the control API:

    # curl --unix-socket /path/to/control.unit.sock \
           http://localhost/config/ > config.json


    Control socket path may vary; run unitd --help or see Startup for details.

    This creates a JSON file with Unit’s current settings; update it with your project settings as follows.

    Suppose you use a basic directory structure for your Django project:

    |-- app1/
    |   |-- ...
    |-- app2/
    |   |-- ...
    `-- project/
        |-- ...

    Edit the JSON, adding a listener entry to point to a Unit app with your project’s WSGI module; the project and its apps will run on the listener’s IP and port. If you use a virtual environment, reference it as home:

        "listeners": {
            "": {
                "pass": "applications/django_project"
        "applications": {
            "django_project": {
                "type": "python 3",
                "path": "/home/django/project/",
                "home": "/home/django/venv/",
                "module": "project.wsgi"


    Mind that Unit will look for an application callable in the WSGI module to run the entire project.

    Here, the top-level project directory becomes path; its child project and the in it are imported via module. If you reorder your directories, set up path and module accordingly.

  4. Upload the updated configuration:

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config

    After a successful update, your project and apps should be available on the listener’s IP address and port:

    $ curl
    $ curl