Deploy Django Web App on IIS

deploy django on iis

Many people might find it not a good solution to deploy Django web applications on IIS but sometimes we really need to do when we have only a windows server. In this post I will guide you step by step that how can we host a Django web application on IIS server. This tutorial is tested on windows 10 and windows server 2016.

Step 1 – First Install python for all users on windows. Follow this – Install python in windows.

Step 2 – Then Create a virtual environment for your Django web application, activate it, and install all requirements for your Django web application. Follow this – Create virtual environment.
Also, install wfastcgi in your virtual environment using pip install wfastcgi

Step 3 – Ater that, Install IIS on windows with the CGI feature. Follow this blog.
At this point make sure you are able to access http://localhost from your browser which will show the default IIS site.
If not then see if all services for IIS are running.

iis default website

FastCGI Settings

Step 4 – Next, Open IIS Manager and double click on “FastCGI Settings” as shown in picture.

Step 5 – Now you will see “Add Application” under the Actions section on the right pane. Click on “Add Application”

A popup window will open with the title “Add FastCGI Application”
Now in Full path box add the python script from your virtual environment.
And in the Argument box add the file from your virtual environment.
At this point the window should look like this.

deploy django web apps on iis
Then in General section > Environment Variables click on three dots “…” button next to “(Collection)”, Please note the button will only appear when you click on Environment Variables.
After clicking “…” button you will see the window look like this

FastCGI Environment Variables

fastcgi environment variables
In the Members, section click on Add to add a Member.
Now your screen should look like this

Now in the Name section write “DJANGO_SETTINGS_MODULE” and in the value section write “learning_users.settings”
Please note that “learning_users” is the name of my project level app in the Django project where the file exists replace “learning_users” with your’s name.

Now add two more variables with the following Names and Values.
Value = learning_users.wsgi.application
Replace learning_users with your’s name.

Value = C:\PythonWebApps\MyProject
Please note that this path should be the root of your project where file exists.
Now the screen should look like this

deploy django web applications on iis
Note – All Variables are case sensitive
Now click on OK to close EnvironmentVaribales Collection Editor.
Again click OK to close Add FastCGI Application Editor.

Step 6 – Django Web Applications on IIS deployment

Now Open the IIS Manager, Expand the server name, Right-click on Sites, and click “Add Website…”
In “Add Website” Dialog enter the name of the website whatever you want.
In “Physical Path” browse and select the root folder of your Django project where file exists.

Then click on “Test settings” and verify that you don’t have any warnings related to authorization. If there is then try the “Connect As” option and select the user which has administrator access to that computer. If still you have warnings then go to the project folder properties and give full control access to Users.

Port Settings

Now change the port to 81 because on 80 already IIS default website is running. In the real-world we use hostnames and use the same port 80 and the site is selected and the request is processed by the hostname header by the IIS.
For now change it to 81 and leave the hostname blank.
Click OK.

Step 7 – Handler Mappings

Then double click on your website and then in middle pane select Handler Mappings as shown in picture

iis site settings

Now on the right pane under Actions click on “Add Module Mapping…” as shown in picture

iis handler mapping for django

Module Mapping Settings

Then in “Add Module Mapping” Dialog.
A – After that Type * in Request Path
B – Then Select FastCgiModule in Module Textbox.
C – And In “Executable(Optional)” section write the following with a pipe separator
D -Finally In the “Name” Section write anything.
Note – Replace the environment path as we did in previous steps the paths are different in the below picture as I captured from an existing project, use the paths from your virtual environment.
The picture is shown here

deploy django web apps on iis

E – Then click the “Request Restrictions” button and uncheck the “Invoke handler only if request is mapped to” checkbox
After that click OK to close Request Restriction Dialog.
Now click OK to close Add Module Mapping Dialog.

Step 8 – The Last Thing

Finally, add hostname in the file otherwise you will get an error while accessing the website.
ALLOWED_HOSTS= [‘localhost’,’server_ip’]

For more information on IIS go to –

And We have done. Now open your browser and type http://localhost:81 you will see your website is running. Thanks for reading the tutorial for “Deploy Django web applications on IIS”

Note – You might see some performance issues like the process will terminate after some time if no request comes in. Must follow “Improve performance of Django and flask on IIS “to fix everything else.

Related posts

6 Thoughts to “Deploy Django Web App on IIS”

  1. Anonnymous

    I am regular reader, how are you everybody?
    This piece of writing posted at this web page is truly nice.

  2. Nnoc

    I have tried to follow like 5 different “tutorials” that I found online to configure this thing, but all left out steps or were vague with some settings. Yours was perfect and went over everything I needed to do. Thank you!

  3. Cinda

    I’m not sure the place you are getting your information, but good topic.
    I must spend a while studying more or working
    out more. Thank you for fantastic information I was looking for
    this information for my mission.

  4. camo phone case

    I am sure this paragraph has touched all the internet users, its
    really really pleasant piece of writing on building up new blog.

  5. Way cool! Some very valid points! I appreciate you penning this write-up and also the rest
    of the website is really good.

Leave a Comment