Running a Django app on Windows IIS


In most cases, I would recommend using a 'unix' OS and nginx for running your Django application. However, there are times that it's necessary for you to use Windows and IIS.

This is a compilation of a few tutorials and Stack Overflow answers. I've referenced them at the section in the bottom.


I assume the following has already been setup:

  • IIS 7+ with the CGI module is installed on your machine
  • Python 2.7+/3.4+ with pip and django are already installed
  • You already have an example Django application and know how to edit it

If you don't have IIS installed:

If you don't have a Django application created and don't know how, then I suggest reading through Django's documentation which is not only very documented, but also has quite a few useful tutorials. Note: I've linked to the 'dev' branch of documentation to make this tutorial a little more relevant over time. However, it's important you use the documentation of the actual version of Django you have installed.

Note: This guide works for native and environment based Python installation. I personally used an Anaconda Environment without any issues. It's assumed from the rest of this guide, that you're working in this environment.

Installation and Setup

There are two major steps to take when installing and setting up Django to be used on IIS.

  1. Installing and enabling wfastcgi
  2. Configuring IIS for Django

Installing and enabling wfastcgi

Summary (tl;dr)

  1. pip install wfastcgi
  2. wfastcgi-enable

Detailed Explanation

First off, we need to install wfastcgi using pip (or you preference of installation method):

    pip install wfastcgi

wfastcgi was created by the Python Tools for Visual Studio people, but PTVS isn't required. If you find any issues with wfastcgi you can file a report on their Github repo.

After installing you need to enable wfastcgi you need to enable it:


You may need to use the full file path:

    <path to python install>\scripts\wfastcgi-enable

Configuring IIS for Django

Summary (tl;dr)

  1. Add Handler Mapping
  2. Set Root folder for IIS Site

A file called web.config should be created in root folder of you Django Site (same location as your file). Here's a template:

<?xml version="1.0" encoding="UTF-8"?>
                <add name="Python FastCGI" 
                     scriptProcessor="<Path to Python>\python.exe|<Path to Python>\lib\site-packages\" 
            <add key="WSGI_HANDLER" value="<WSGI_HANDLER based on Django Version>" />
            <add key="PYTHONPATH" value="<Path to Django App>" />
            <add key="DJANGO_SETTINGS_MODULE" value="<Django App>.settings" />


WSGI_HANDLER: this configuration is dependent on the version of Django you're running:

  • Django 1.7+: django.core.wsgi.get_wsgi_application()
  • Otherwise: django.core.handlers.wsgi.WSGIHandler()

Example web.config:

<?xml version="1.0" encoding="UTF-8"?>
            <add name="Python FastCGI" 
        <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
        <add key="PYTHONPATH" value="C:\inetpub\wwwroot\HelloWorld" />
        <add key="DJANGO_SETTINGS_MODULE" value="HelloWorld.settings" />


Here are a few issues that I can into while setting this up.

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

If you get this error, then that means you're probably using the wrong WSGI_HANDLER option for your version of Django.

Exception: WSGI_HANDLER env var must be set

This means that your web.config doesn't have the correct app keys configured and is missing the WSGI_HANDLER environment variable.

Static Files

Within the folder that you store your static files you'll need to add this

    <?xml version="1.0" encoding="UTF-8"?>
      <remove name="Python FastCGI" />


Python and IBM Rational DOORS

There's been a few times now that I've wanted to use Python to analyze content within the IBM Rational DOORS database. So I started searching. To my excitement I found this article but after trying to view the examples and finding out they're dead links it was back to square one.

After reading the DOORS Api Manual I was able to finally figure things out. Before we continue, you'll need the following batchserver.dxl file saved on your local machine:

// batchserver.dxl
IPC ipc = server 5093
string request
/* add functions for you interface here */
while (true) {
    if (accept(ipc)) {
        if (!recv(ipc, request)) {
            warn "Server has disconnected"
    } else {
        warn "error accepting client connection"

    print "request: "
    print request
    print "\n"
    errors = false
    if (request == "shutdown_") {
        send(ipc, "done_")

    if (request == "errors_")

    if (request == "quit_")

    ans = eval_ request
    if (ans == "errors in eval_ string") {
        print "errors in request\n"

    send(ipc, ans)

Here's the basic overview of how to connect to DOORS using Python:

  1. Startup DOORS using the batch mode and run the script above:

    doors -U <username> -p <password> -batch <path to batchserver.dxl>
  2. Create a Socket Connection to the batch server and send a dxl command:

    import socket
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(("", 5093))
    s.send('print "Hello World"')

It's actually pretty simple from there. You can pass in custom DXL scripts via the python socket connection. If you want to pass data back from the DXL socket server to Python, you'll need to use the return_ command in the DXL. Here's an example:

import socket

dxl_command = b"""
Object o
string s = ""
Module m = read("<path to Module>", false)
for o in all(m) do {
    s = s identifier o "\\n"
return_ s

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("", 5093))
test = s.recv(1024)


Installing OpenCV and ffmpeg on Windows

OpenCV and ffmpeg are great tools especially if you're wanting to do any type of image/video analysis or manipulation. But installing these tools isn't exactly the easiest thing to do either. I went through the pain and here's what I discovered.

Installing ffmpeg

Since opening most video files require a codec in OpenCV installing ffmpeg was the first thing that I did.

  1. Download the latest static build for Windows and then extract the files. You may need 7zip to extract.

  2. Create a folder in C:\ called ffmpeg

  3. Copy the contents of the extracted files into C:\ffmpeg

  4. Edit your PATH environment variable to append at the end the following entry:

  5. Confirm that everything is working correct by opening a cmd prompt and enter the following (Note you might need to run cmd as administrator):

    ffmpeg -version

Installing OpenCV

These steps are similar to installing ffmpeg however the OpenCV download comes with a self-extracting executable.

  1. Download the self-extracting executable from the OpenCV website

  2. Run the Executable which will in turn extract the executable

  3. Create a folder in C:\ called opencv

  4. Copy the contents of the extracted files into opencv

  5. Edit your PATH environment variable. This will be dependent on the version you want installed (i.e. 32 or 64 bit) and also the version of visual studio you have installed (express editions are fine).

    | <OS Version> | Definition |
    |     x86      | 32 bit     |
    |     x64      | 64 bit     |
    | <vs version> | Definition |
    |  vc10        | VS 2010    |
    |  vc11        | VS 2012    |
    |  vc12        | VS 2013    |
    C:\opencv\build\<OS Version>\<vs version\bin

After installing both OpenCV and ffmpeg you'll need to restart your computer to add the paths to the system path.

Installing OpenCV Python

Installing the binding for OpenCV in python simply requires copying over cv2.pyd from opencv/build/python/2.7/<OS Version> in to the site-packages folder. Note: that currently OpenCV is ONLY supported on Python 2.7.

OpenCV also requires that numpy be installed as well. matplolib is also recommended to be installed.

To test it out open a python console and enter the following:

    import cv2

Developing a Cross Platform Mobile Application Part 1

I've been contracted to create a simple application for a local school, that basically takes all of their social media feeds, and puts them in one central place (i.e. Twitter, facebook, youtube, etc,.). They wanted me to develop for all three major platforms (Android, iOS, and Windows Phone 8). I was planning on developing for each platform individually, even though I knew that the basic business logic behind all three were going to be pretty much the same. So I thought that I'd ask over at Stack Overflow if there was any way to keep the business logic between all three platforms:

What languages have multi-platform support for app developement?

This led me to the tool Xamarin. Apparently it allows you to develop Android, and iOS apps using C# libraries. Since Windows Phone 8 already uses C# this sounds like a win-win situation... til I saw the price $299 per platform for the "indie" which means you have to use their IDE, or $999 again per platform to use their add in for Visual Studio. I've decided to give it a shot, and since I'm still a student I was able to secure an Academic License (which thankfully includes the Visual Studio add-ins) that was a bit cheaper. (Thanks guys. Honestly.)

So here's the basic idea of what Xamarin is and does:

Shared backend business logic, custom UI generation

Each platform is unique in its development. There are things that are very unique to iOS that aren't found on Android, and vice versa. However, the backend logic or how the data is stored, retrieved, and manipulated can be the same all around. This graphic gives a good overview of what Xamarin achieves to accomplish seemless cross platform development:


Installation was simple, until it came time to connect Xamarin to Visual Studio. As of right now, Xamarin doesn't support Visual Studio 2013 preview (understandable). After installing VS 2012 Ultimate, the Xamarin installer detected that the extensions needed to be installed. I tried, and tried, and tried, and tried, to no avail. Finally, I completely uninstalled Xamarin, and VS 2013 preview and then reinstalled Xamarin. Everthing worked fine from there.

If you're going to develop for iOS be warned, you still need a Mac running machine. You can still supposedly run the app from the Windows environment but, this appears to be done via connecting remotely to Xcode on the Mac. This also measn that you'll need to Xamarin on the Mac as well.


To summarize, if you're looking to develop mobile apps utilizing a single tool, Xamarin is your only option so far. But keep in mind there's a lot of upfront cost and setup time to get the ball rolling. Here's a quick summary of the steps that I've taken to get this all up and running:

  1. Installed Visual Studio 2012 Ultimate
  2. Installed Windows Phone 8 SDK
  3. Installed Xamarin using the Universal installer on Windows Machine
  4. While installing on Windows, I also installed on the Mac
  5. Activated Xamarin on both Mac and Windows Machine
  6. Started creating the project using this guide

Using Anaconda and PTVS

Visual Studio is my favorite IDE by far, and when I heard that Python Tools for Visual Studio (PTVS) upgraded to v2.0 beta I was excited to test out the new features. However, I just started using Anaconda as my main Python distro which leads to problems with PTVS detecting any environments created using Anaconda.

Note that I'm not talking about virtualenvs, but rather Aanaconda's environments

I was able to get a Python 3.3 environment installed and running on Visual Studio, and here's what I did.

Installing a new Python Environment using Anaconda

To install a new env for Python, open up a command prompt and run the following:

conda create -n py3k python=3.3

You can change py3k to whatever you want to name the environment. The Python=3.3 specifies the version of python to install. Anaconda will take care of everything for you as far as downloading and installing packages.

Setting up PTVS for the new Anaconda Environment

PTVS will automatically pick up the root Anaconda environment, but any new ones created need to be specifically referenced. You can do this manually within Visual Studio:


Tools --> Options --> Python Tools --> Interpreter Options

Add Interpreter

And then give it a new name. I simply named it Python 3.3. Assuming you installed Anaconda in the default path and name the environ, use the following for the Path and Windows Path:

C:\Anaconda\envs\{env name}\python.exe
C:\Anaconda\envs\{env name}\pythonw.exe

Select the appropriate architechture and Language Version for your environment. Finally, you'll need to create a new Environment Variable for this installation. I simply used ANAPYTHONPATH. Whatever var you use, be sure to set the value of it to the following:

C:\Anaconda\envs\{env name};C:\Anaconda\envs\{env name}\Scripts

That's it! You should have full access to your new Anaconda Environment.

Hello World

Welcome to the KronoSKoderS blog! I'll be sharing my random musings with the projects that I plan on working on. Right now I'm only working on a couple, but hope to start up a few more. Here's a quick list of the things that I'm working on:

  • Metro-SE: A Winows 8 and Windows Phone 8 interface to the Stack Exchange sites
  • Alerts-SE: A notification systems for the Stack Exchange sites

Well this post doens't contain a whole lot, but just wanted to get started on things. Hopefully I'll be able to add a few more things later as I go along.