Skip to main content

Helper Management commands to host Django applications on Windows Servers.

Project description

django-windows-tools is a Django application providing management commands to host Django projects in Windows environments.

It provides management commands allowing to:

  • Host a Django application behind IIS as a FastCGI application (requires IIS 7 and Up).

  • Run Celery and Celery Beat background processes as a Windows Service.

It requires Django >= 1.4 and pywin32.

Compatibility notes

  • django-windows-tools 0.1.3 is the last version to work with Django <= 1.7

  • the win_fcgi part is known to work with Django versions up to 1.11 and Python 3.6 (django-windows-tools 0.2 needed), and works with IIS up to version 10

  • installing services with newer versions of Django and Python 3 is not tested and may not work (see also the open issues)

  • newer Celery versions cannot be installed as a service as described (see #19)

The following gives a Quick overview of the project. For more information, please read the Project documentation.

Installation and Configuration

You install the application with the command:

pip install django-windows-tools

Or you may install the latest development version for more fixed bugs:

pip install git+

Enable the django_windows_tools application to be able to use the management commands. Add the app to the project’s list in


FastCGI Configuration


On the host machine, you need to have :

  • IIS 7 or better installed and running.

  • The CGI module installed.

To host your Django project under IIS with the binding, you need first to collect your static files with the command:

D:\sites\mydjangoapp> python collectstatic

And then run the following command with Administrator privileges :

D:\sites\mydjangoapp> python winfcgi_install --binding=

The command will do the following:

  • Create the FastCGI application to serve your Django application dynamic content.

  • Create a site name mydjangoapp with the binding pointing to the root of your project.

  • Install a web.config file in the root of the project that handles the redirection of requests to the Django application.

  • Create if needed a virtual directory to handle the serving of your static files through IIS.

To remove the site created with the preceding command, type:

D:\sites\mydjangoapp> python winfcgi_install --delete

the winfcgi_install command provides numerous options. To list them, type:

D:\sites\mydjangoapp> python help winfcgi_install

More information on how the configuration is done is provided in this Blog post.

Running Celery or other Background commands as a Windows Service

With the application installed, on the root of your project, type the following command:

D:\sites\mydjangoapp> python winservice_install

It will create two files, and service.ini in the root directory of your project. The first one will help you install, run and remove the Windows Service. Ther later one contain the list of the management commands that will be run by the Windows Service.


The service.ini is a configuration file that looks like the following:

# Services to be run on all machines

# There should be only one machine with the celerybeat service
run=celeryd celerybeat

parameters=-f d:\logs\celery.log -l info

parameters=-f d:\logs\beat.log -l info --pidfile=d:\logs\

# Runs the debug server and listen on port 8000
# This one is just an example to show that any manage command can be used
parameters=--noreload --insecure


The services section contains :

  • The list of background commands to run in the run directive.

  • The list of files to delete when refreshed or stopped in the clean directive.

You can have several services sections in the same configuration file for different host servers. The Windows Service will try to find the section which name matches the name of the current server and will fallback to the services section if it does not find it. This allows you to deploy the same configuration file on serveral machines but only have one machine run the celery beat background process. In the preceding configuration, only the server named BEATSERVER will run the celerybeat command. The other ones will only run the celeryd command.

For each command name specified in the run directive, there must be a matching configuration section. The section contains two directives:

  • command specifies the command to run.

  • parameters specifies the parameters to the command.

In the previous configuration file, the celeryd configuration will spawn a process that will run the same command as :

D:\sites\mydjangoapp> python celeryd -f d:\logs\celery.log -l info

Lastly, the log section defines the log level and the the log destination file for the Windows Service.

Installation and start

The windows service is installed with the following command (run with Administrator privileges) :

D:\sites\mydjangoapp> python --startup=auto install

It is started and stopped with the commands:

D:\sites\mydjangoapp> python start
D:\sites\mydjangoapp> python stop

It can be removed with the following commands:

D:\sites\mydjangoapp> python remove

The Windows Service monitor changes to the service.ini configuration file. In case it is modified, the service does the following:

  • Stop the background processes.

  • Reread the configuration file.

  • Start the background processes.


The winservice_install management command provides several options allowing to customize the name of the web service or of the script name. To obtain information about them, type:

D:\sites\mydjangoapp> python help winservice_install

Project details

Download files

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

Source Distribution

django-windows-tools-0.2.1.tar.gz (24.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page