[PYTHON] How to run Django on IIS on a Windows server

This procedure is omitted below

Creating a virtual environment

Move to the target directory and execute the following

python -m venv venv

Install Django and wfastcgi

First, enable venv

venv\Scripts\activate.bat

If you want to use Django with IIS, you need wfastcgi, so install it as well.

(venv)> pip install django
(venv)> pip install wfastcgi

Enable wfastcgi

(venv)> venv\Scripts\wfastcgi-enable.exe

OK if it comes out as follows

Configure configuration changes Commit path"MACHINE/WEBROOT/APPHOST"of"MACHINE/WEBROOT/APPHOST"Section"system.webServer/fastCgi"Applied to
"d:\webroot\venv\scripts\python.exe|d:\webroot\venv\lib\site-packages\wfastcgi.py" can now be used as a FastCGI script processor

The output will be used later.

d:\webroot\venv\scripts\python.exe|d:\webroot\venv\lib\site-packages\wfastcgi.py



# Unlock system.webServer / handlers

(venv)> %windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/handlers


 OK if it comes out as follows

Configuration path"MACHINE/WEBROOT/APPHOST"Section"system.webServer/handlers"Unlocked.


# Allows Python files to be executed with handler mapping.

 Set as follows in [Site]-> [Handler Mapping]

 scriptProcessor should use the result obtained by ``` wfastcgi-enable.exe```. ![2020-10-19_13h16_51.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/247515/1260b0b6-a967-8679-b8ae-0c3495f38072.jpeg)

# Creating web.config

 Create the following file and place it in the Django root directory.


#### **`web.config`**
```xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appSettings>
        <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
        <add key="PYTHONPATH" value="D:\webroot" />
        <add key="DJANGO_SETTINGS_MODULE" value="app.settings" />
    </appSettings>
    <system.webServer>
        <handlers>
            <add name="Python FastCGI"
                 path="*"
                 verb="*"
                 modules="FastCgiModule"
                 scriptProcessor="d:\webroot\venv\scripts\python.exe|d:\webroot\venv\lib\site-packages\wfastcgi.py"
                 resourceType="Unspecified" />
        </handlers>
    </system.webServer>
</configuration>

You are now ready.

Recommended Posts

How to run Django on IIS on a Windows server
How to live a decent life on 2017 Windows
Verification of how to periodically execute a script on a Linux server on Windows
How to deploy a Django application on Alibaba Cloud
How to run a Django application on a Docker container (development and production environment)
How to use Dataiku on Windows
How to install pycrypto on Windows
How to deploy django-compressor on Windows
How to run matplotlib on heroku
Run TensorFlow2 on a VPS server
How to install music 21 on windows
How to use GitHub on a multi-person server without a password
How to run a trained transformer model locally on CloudTPU
Don't lose to Ruby! How to run Python (Django) on Heroku
How to mount a Windows 10 directory on Ubuntu-Server 20.04 on VMware Workstation 15
I tried to create a server environment that runs on Windows 10
A note on how to check the connection to the license server port
[Kivy] How to install Kivy on Windows [Python]
How to use Google Assistant on Windows 10
How to deploy a Django app on heroku in just 5 minutes
How to run Cython on OSX Memo
How to continue processing after returning a response on aiohttp Server
Run Jupyter notebook on a remote server
Run matplotlib on a Windows Docker container
How to run a Maya Python script
A story about trying to run JavaScripthon on Windows and giving up.
How to make a process thread run only on a specific CPU core
Rock-paper-scissors with Python Let's run on a Windows local server for beginners
Run django applications on Windows + Apache + mod_wsgi + services.
Put MicroPython on Windows to run ESP32 on Python
How to develop a cart app with Django
How to run MeCab on Ubuntu 18.04 LTS Python
How to quickly install h5py on Windows 10 [Unofficial]
How to set up a local development server
How to create a Rest Api in Django
[Python] How to install OpenCV on Anaconda [Windows]
How to install / verify graphviz on anaconda / windows10
Run Django on PythonAnywhere
How to embed mod_wsgi into Apache on Python Windows
Apache + Django + Shibboleth on Windows Server 2016 Related Articles Summary
How to install Linux on a 32bit UEFI PC
A memorandum on how to use keras.preprocessing.image in Keras
How to run Self bot on Discord.py [Easy vandalism! ]
How to create a simple TCP server / client script
How to use Django on Google App Engine / Python
I'm a windows user but want to run tensorflow
How to reference static files in a Django project
How to build a Python environment on amazon linux 2
How to operate Firefox with selenium on Windows Memo
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
How to install Python [Windows]
How to call a function
How to register on pypi
How to hack a terminal
Django environment development on Windows 10
How to run Notepad ++ Python
Run Jupyter Notebook on windows
How to use Fujifilm X-T3 as a webcam on Ubuntu 20.04
A memo on how to easily prepare a Linux exercise environment
How to build a new python virtual environment on Ubuntu