Published on

Python Django - How to deploy one or many django-websites using IIS

Authors

Hello everyone,

Today I'm gonna make a tutorial about deploying Django with IIS. With IIS, you can deploy one or many projects.

img

Let's find out !!!

  1. Create a folder project on "D:\" or wherever you want, then install virtualenv with: pip install virtualenv
img
  1. Create ENV in project folder with: virtualenv venv. Activate venv with command: venv\Scripts\active. It will appear (venv) in front of the command line
img
  1. Install django and wfastcgi with: pip install django wfastcgi. Then create django project on the folder you created above. Example: django-admin startproject testiis
img
  1. Open IIS, create a new website, change the Physical path to your Django Project. I'm using port 88 because my other project took port 80.
img
  1. Click to the main Server and choose FastCGI Settings Full-Path you will fill with the path to the python.exe in venv. And Arguments is the path to wfastcgi.py in venv like this:
img
img
  1. Then choose Handler Mappings to set up Module Mapping. Click Add Module Mapping...
img
  1. An windows popup, fill in the form like this.

Request path: * Module: You choose FastCgiModule Executable: path\to\venv\python.exe|path\to\venv\wfastcgi.py Then click Request Restrictions..., untick the Invoke handle ....

img
img
  1. Then click OK, a popup shows out, click No
img
  1. A file with the name web.config will appear in the django project 's folder, add some config above the <system.webServer>
<appSettings>
    <!-- Required settings -->
    <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
    <!-- Your django path -->
    <add key="PYTHONPATH" value="D:\MyDemo\testiis" /> 
    <!-- Your djangoname.settings -->
    <add key="DJANGO_SETTINGS_MODULE" value="testiis.settings" />
</appSettings>
  1. Now you can run website with your domain and port you setup above
img