- Published on
Python Django - How to deploy one or many django-websites using IIS
- Authors
- Name
- Beyonder Luu
- @beyonderluu
Hello everyone,
Today I'm gonna make a tutorial about deploying Django with IIS. With IIS, you can deploy one or many projects.
![img](/_next/image?url=%2Fblog%2Fdjango%2F2%2F1.png&w=1920&q=75)
Let's find out !!!
- Create a folder project on
"D:\"
or wherever you want, then install virtualenv with:pip install virtualenv
![img](/_next/image?url=%2Fblog%2Fdjango%2F2%2F2.png&w=1920&q=75)
- 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](/_next/image?url=%2Fblog%2Fdjango%2F2%2F3.png&w=1080&q=75)
- 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](/_next/image?url=%2Fblog%2Fdjango%2F2%2F4.png&w=1920&q=75)
- 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](/_next/image?url=%2Fblog%2Fdjango%2F2%2F5.png&w=750&q=75)
- 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](/_next/image?url=%2Fblog%2Fdjango%2F2%2F6.png&w=828&q=75)
![img](/_next/image?url=%2Fblog%2Fdjango%2F2%2F7.png&w=828&q=75)
- Then choose Handler Mappings to set up Module Mapping. Click Add Module Mapping...
![img](/_next/image?url=%2Fblog%2Fdjango%2F2%2F8.png&w=828&q=75)
- 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](/_next/image?url=%2Fblog%2Fdjango%2F2%2F9.png&w=828&q=75)
![img](/_next/image?url=%2Fblog%2Fdjango%2F2%2F10.png&w=828&q=75)
- Then click OK, a popup shows out, click No
![img](/_next/image?url=%2Fblog%2Fdjango%2F2%2F11.png&w=828&q=75)
- 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>
- Now you can run website with your domain and port you setup above
![img](/_next/image?url=%2Fblog%2Fdjango%2F2%2F12.png&w=1920&q=75)