Professional Documents
Culture Documents
This short, focused tutorial walks you through the basic setup of a Django project on
Windows. It covers the installation of Python, activating environment.
1. Install Python:
1. Download the latest Windows x86–64 executable installer from https://python.org
2. Double-click the Python installer. If you get a security warning at this point, click
“Run” to continue.
4. On the Optional Features step, leave the default settings and click “Next”
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 1/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
Check the “Install for all users” box (note that this will also check the “Precompile
standard library” box)
In the input box below “Customize install location” change the value to the
following: C:\Python35
6. Click “Install”
Type python and press Enter. This should open a Python interpreter:
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 2/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
If instead of seeing the Python interpreter you see the error “‘python’ is not recognized as
an internal or external command …” this likely means the “Add Python to environment
variables” box was not checked on the Advanced Options step of the installation process. If
this occurs you can uninstall and reinstall Python and make sure to check the “Add Python
to environment variables” checkbox, or add the following to the System environment
“Path” variable:
C:\Python35;C:\Python35\Scripts
. . .
5. Create a new virtual environment. We’ll use the name foo for the purposes of
illustration. Note that if you change this, you’ll have to adjust the rest of the steps in
this post accordingly. python -m venv Eric [then press Enter]
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 3/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
With the virtual environment created, the next steps are to activate the virtual
environment and update pip, Python’s package installer.
At this point you will see (Eric) at the beginning of the command prompt,
indicating the virtual environment is active:
Once a virtual environment is active, all Python-related commands such as python, pip,
etc. will be executed against the active virtual environment. For example, with the virtual
environment active if a package is installed with pip, that package will only be available in
the virtual environment, not in the system’s global Python environment.
Next, to ensure we don’t run into installation or security issues with pip, let’s upgrade
it:
In the same Command Prompt, you opened above, with the virtual environment
activated, run the following command:
python -m pip install — upgrade pip [then press Enter]
Then install all the dependent modules and packages related to the project using
command and make sure you are running it in same path where requirement.txt
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 4/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
. . .
Open the gitbash and go to the path where you want to copy your project.
Download the project from git using command in git bash: git clone
https://github.com/ayushi21095/User_details.git
Go to the path where your project file is located in command prompt where virtual
environment was activated.
In the Command Prompt with the virtual environment activated, install Django:
pip install wfastcgi [then press Enter]
Start the Django development server: python manage.py runserver [then press
Enter]
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 5/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
Go back to the Command Prompt and press Ctrl-C to stop the Django development
server.
. . .
4. Install IIS
Even if you already have IIS installed, you may need to go through these steps to install
the CGI feature if it wasn’t installed as part of the original IIS installation.
In the search box in the top right, type “windows features” (without the quotes)
In the search results under “Programs and Features” click “Turn Windows features
on or off.” This launches the Add Roles and Features Wizard.
Enter http://localhost in the address bar and press Enter. You should see the default
IIS page.
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 6/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
Scroll to the bottom of the list and ensure you see “World Wide Web Publishing
Service” listed, and that the status is “Running”.
. . .
Installed Python
With all the underlying infrastructure in place, the last step is to configure IIS to serve
Django applications. The Django development server is not designed for production
use, so using a production-quality web server such as IIS is mandatory for production
applications.
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 7/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
As with previous steps you’ll need to adjust accordingly for the actual application you
want to deploy, but for the purposes of this documentation we’ll configure IIS to serve
the test Django application we created in the previous steps.
. . .
Click on the name of the server in the list on the left. If you see the following dialog
box, check the box “Do not show this message” and click “No.” (You can always get
to this later if necessary by clicking “Get New Web Platform Components” under
“Actions” on the right-hand side of IIS Manager.)
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 8/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
In the Add FastCGI Application dialog, in the “Full Path” box, type the path to the
Python executable for the application’s virtual environment:
C:\virtualenvs\Eric\Scripts\python.exe
In the Arguments input box, type the path to the wfastcgi.py file in the application’s
virtual environment:
C:\virtualenvs\Eric\Lib\site-packages\wfastcgi.py
At this point your settings in the Add FastCGI Application dialog should look like
this:
With the Add FastCGI Application dialog box still open, under the “General”
section, click on the “Environment Variables” line, then click the gray “…” button
that appears next to (Collection) on the right-hand side of the line. This opens the
Environment Variables Collection Editor dialog.
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 9/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
In the “Name properties” section on the right, click the input box to the right of
“Name,” remove the “Name” text that is already in the input box, and enter
DJANGO_SETTINGS_MODULE (note that this MUST be entered in ALL CAPS)
Click the input box to the right of “Value” and enter Ericsson.settings
NOTE: All of these settings are CASE-SENSITIVE. They must be entered with exactly the
case indicated here in order to work.
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 10/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
. . .
On the left-hand side under Connections, expand the tree under the server name
by clicking on the arrow to the left of the server name
For the purposes of this example configuration, change the Port to 81, since the
Default site is running on port 80. For a real-world application you’ll likely want to
use name-based virtual hosting by adding bindings and run the site on port 80.
You may leave the “Host name” blank. At this point the Add Website dialog should look
like this:
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 11/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
Click “OK”
Next, we’ll add a FastCGI handler mapping to this site so the requests coming into the
site will be processed by the Django application.
In IIS Manager, expand the Sites folder on the left-hand side and click on the site
Click the arrow on the right-hand side of the “Module” box and select “FastCgi
Module”
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 12/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
Note that the character after python.exe is a pipe (|), which is entered by pressing Shift-\
on your keyboard
In the “Name” box, enter Django Handler (you can call this whatever you want; it’s
merely a friendly name for the module mapping)
The Add Module Mapping dialog should now look like this:
Click the “Request Restrictions” button and uncheck the “Invoke handler only if
request is mapped to:” checkbox
When prompted “Do you want to create a FastCGI application for this executable?”
click “No” since we created the application earlier.
Note that you CAN have it create the FastCGI application for you from the module
mapping, but the settings seem to be different and the end result isn’t fully editable. I also
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 13/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
detailed how to create the FastCGI application to be as thorough as possible with all the
various pieces involved.
You will now see the Django Handler listed in the Handler Mappings for the foo
website:
Browse to http://localhost:81
This is the same result as when we ran the Django test server earlier, but now the
requests are being handled by IIS.
. . .
8. Additional Steps-
Make sure in setting.py file under you project folder you do:
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 14/15
7/31/2020 Steps to Deploy Python Django Web Application on Windows IIS Server | by AYUSHI SHARMA | Medium
1. DEBUG = False
https://medium.com/@ayushi21095/steps-to-deploy-python-django-web-application-on-windows-iis-server-379b2b87fcf9 15/15