Running Django on Windows Using an IIS Server - django

I'm trying to run Django on Windows Using an IIS Server, I'm following a nice tutorial:
https://www.youtube.com/watch?v=CpFU16KrJcQ&fbclid=IwAR37FtYd2ZveEIxBy1FAiqOkp3jpwwjyMQwuGnnaUW_renNHogfrMEbXNUs
I get stuck at the point where I
wfastcgi-enable
Here is the output of the error ..
ERROR ( message:Configuration error
Filename: redirection.config
Line Number: 0
Description: Cannot read configuration file due to insufficient permissions
. )
An error occurred running the command:
['C:\\Windows\\system32\\inetsrv\\appcmd.exe', 'set', 'config', '/section:system.webServer/fastCGI', '/+[fullPath=\'"C:\\Users\\\\pyt
hon.exe"\', arguments=\'"C:\\lib\\site-packages\\wfastcgi.py"\', signalBeforeTerminateSeconds=\'30\']']
Ensure your user has sufficient privileges and try again.
I don't know how to set privileges to accept the command ..
can anybody help?

On server 2012 this error can be caused by UAC which needs to be disabled via the registry.
This article explains why... https://social.technet.microsoft.com/wiki/contents/articles/13953.windows-server-2012-deactivating-uac.aspx
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system
change DWORD "EnableLUA" from 1 to 0

How to Deploy Django Web Application on Windows using Microsoft IIS Server
Deploy Django on Windows using Microsoft IIS
Step 1 : Paste the Project File to C:\inetpub\wwwroot or C:\ Directory or Any other Directory
Step 2 : Install Python in C:\Python because path limit user friendly – Appropriate Version and set path environment variable
Step 3 : Install Microsoft C++ Build Tools https://visualstudio.microsoft.com/visual-cpp-build-tools/
enter image description here
Step 4 : If Microsoft IIS is not Installed, follow these steps : Go to Control Panel -> Program and Features -> Turn Windows Features On or Off -> Select Internet Information Services ( IIS ) -> Select All services as per your project, Check Application Development features all enabled !!! -> Confirm and Continue
enter image description here
Step 5 : Open Microsoft IIS Application – Right Click -> Add Website… -> Enter the Site Name , Select the Physical project path location i.e select manage.py designation folder and enter the binding information
Step 6 : Yes, you successfully created IIS Application Site
Step 7 : Now, you should give access for your project folder and python folder
Step 8 : Select your project folder and right click -> Select Properties -> Security -> Edit Group or user names -> Add -> Select All Object Types, Select the Machine, and last, Enter the object names -> IIS AppPool\your IIS Site name
e.g. IIS AppPool\DjangoWebApplication and check the names in objects if its correct information it get the Application Object Name e.g. DjangoWebApplication then, then select the object name and select full control to the application.. and use the same procedure on python folder also
Step 9 : Now, Is ready for install python libraries., Install all project requirement libraries with also install, pip install openpyxl, wfastcgi.
Step 10 : Open a CMD as Administrator and enter the command wfastcgi-enable
enter image description here
Step 11 : Then, Check on Microsoft IIS -> IIS -> Click FastCGI Settings -> If it is Successfully Configured the Details is found else not found we enter by manually Click Add Application In Name, paste the python executable path location
e.g. c:\python\python.exe , In Argument paste the wfastcgi.py location.. if you don’t know copy from cmd e.g. c:\python\lib\site-packages\wfastcgi.py and remaining all same okay and continue
enter image description here
Step 12: Create a file web.config nearby manage.py file and enter the details,
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI"
path="*"
verb="*"
modules="FastCgiModule"
scriptProcessor="C:\Python\python.exe|C:\Python\Lib\site-packages\wfastcgi.py"
resourceType="Unspecified"
requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="my_app.wsgi_app()" />
<add key="PYTHONPATH" value="C:\MyApp" />
<add key="DJANGO_SETTINGS_MODULE" value="my_app.settings" />
<!-- Optional settings -->
<add key="WSGI_LOG" value="C:\Logs\my_app.log" />
<add key="WSGI_RESTART_FILE_REGEX" value=".*((\.py)|(\.config))$" />
<add key="APPINSIGHTS_INSTRUMENTATIONKEY" value="__instrumentation_key__" />
<add key="WSGI_PTVSD_SECRET" value="__secret_code__" />
<add key="WSGI_PTVSD_ADDRESS" value="ipaddress:port" />
</appSettings>
</configuration>
From here, you have to change according to your system perspective
First, Change scriptProcessor settings e.g. "c:\python\python.exe|c:\python\lib\site-packages\wfastcgi.py" can now be used
Second, change <add key="WSGI_HANDLER" value=" DjangoWebApplication.wsgi.application" />
Third, change <add key="PYTHONPATH" value="C:\DjangoWebApplication folder" />
Fourth, change <add key="DJANGO_SETTINGS_MODULE" value=" DjangoWebApplication.settings" />
Then, remaining optional !
Step 12: Then, Create another file web.config from static folder and enter the details,
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<clear />
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
</handlers>
</system.webServer>
</configuration>
Step 13 : Then, Create another file web.config from media folder and enter the details
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<clear />
<add name="StaticFile" path="*" verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Script" allowPathInfo="true" preCondition="" responseBufferLimit="4194304" />
</handlers>
<directoryBrowse showFlags="Date, Time, Size, Extension, LongDate" />
</system.webServer>
</configuration>
Step 14 : Open Internet Information Services (IIS) Manager. Under connections select the server, then in the center pane under Management select Configuration Editor. Under Section select system.webServer/handlers. Under Section select Unlock Section. This is required because the C:/inetpub/wwwroot/web.config creates a route handler for our project.
Step 15 : Add Virtual Directory. In order to enable serving static files map a static alias to the static directory, C:/inetpub/wwwroot/webproject/static/
Step 16 : Add Virtual Directory. In order to enable serving static files map a static alias to the static directory, C:/inetpub/wwwroot/webproject/static/
Step 17 : Yes, Now is ready for hosting the site before check the settings.py edit the Allowed Host and add the IP Address and port number
Step 18 : Then, generate the staticfiles by Django run the command python manage.py collectstatic
Step 19 : Now, Is All Set… Start the Server and check all is working correct
Thanks, Johnny https://github.com/Johnnyboycurtis/webproject for your clear explanation...
Try These, Deploy your Website... Cool... !
Reference :
https://pypi.org/project/wfastcgi/
https://learn.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2019

Related

IIS django HttpPlatformHandler infinite loading

so i tried to do Http Platform Handler but now i am in an infinite loading screen when i visit localhost.
this is my configfile
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="C:\Python310\python.exe"
arguments="C:\inetpub\Comsroomform\Home manage.py runserver --port 80"
stdoutLogEnabled="true"
stdoutLogFile="c:\home\LogFiles\python.log"
startupTimeLimit="60"
processesPerApplication="16">
<environmentVariables>
<environmentVariable name="SERVER_PORT" value="80" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
and after a long while of loading this shows up
i was told to follow this tutorial: https://halfblood.pro/running-flask-web-apps-on-iis-with-httpplatformhandler/
You can refer to the following steps to host a Django web application using Httpplatformhandler.
For Django physical path is a path to manage.py of your application.
Download and Install Httpplatformhandler on IIS using Windows Platform
Installer. Or download from this link.
Django APP with Httpplatformhandler Add web.config where your Django
app is defined.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"
requireAccess="Script" />
</handlers>
<httpPlatform startupTimeLimit="10" startupRetryCount="10" stdoutLogEnabled="true"
processPath="C:\Users\user\AppData\Local\Programs\Python\Python36\python.exe"
arguments="manage.py runserver">
<environmentVariables>
<environmentVariable name="foo" value="bar"/>
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
HttpPlaform is handling the Python process. ProcessPath
is a physical path to python executable. Just like you provide python
path in a windows environment variable. To access the python
executable. Here you have to provide python.exe in processPath.
Arguments are the same argument you pass running any python web
application. For eg. python manage.py runserver where app.py to port
number all are arguments. In the above application, manage.py
runserver is passed to run Django application.
Add Permission to Django Application and Python folder where your
executable is present.
Open folder properties.
In Security click on Edit then click on Add
Enter object name as IIS AppPool<yourappname>
Click on the check name if its present click ok and allow permissions you wanted to give then apply it.
Run your application
For more information, please refer to this tutorial.

Hosting Django web application on IIS error

My organization has implemented a web application in Django, and we need to host it on a Windows system. We are using Django 3.2.8 and Python 3.8.8.
The Django project is currently stored here:
C:\inetpub\wwwroot\CED_HRAP
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI" path="\*" verb="*" modules="FastCGIModule" scriptProcessor="c:\python38\python.exe|c:\python38\lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<defaultDocument>
<files>
<clear />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
<add value="base.html" />
</files>
</defaultDocument>
<directoryBrowse enabled="false" />
</system.webServer>
<appSettings>
<add key="PYTHONPATH" value="C:\inetpub\wwwroot\CED_HRAP" />
<add key="WSGI_HANDLER" value="CED_HRAP.wsgi.application" />
<add key="DJANGO_SETTINGS_MODULE" value="CED_HRAP.settings" />
</appSettings>
</configuration>
Our settings.py file is located at
C:\inetpub\wwwroot\CED_HRAP\CED_HRAP\settings.py
We are currently seeing this error message:
HTTP Error 403.14 - Forbidden The Web server is configured to not list
the contents of this directory.
Most likely causes:
A default document is not configured for the requested URL, and
directory browsing is not enabled on the server.
How should we configure the default documents in the web.config file so that it links to Django's internal routing (urls.py)?
We followed the instructions here:
https://github.com/Johnnyboycurtis/webproject
(youtube: https://www.youtube.com/watch?v=APCQ15YqqQ0)
You can see that the web.config file in the above repository does not have any default documents specified. We added them to web.config in an effort to resolve the current error.
Have also looked at several other tutorials and documents on this process, but have not been able to resolve the problem.
Thanks!
This problem occurs because the website doesn't have the Directory Browsing feature enabled. Also, the default document isn't configured. To resolve this problem, use one of the following methods:
Method 1: Enable the Directory Browsing feature in IIS
To resolve this problem, follow these steps:
Start IIS Manager. To do it, select Start, select Run, type inetmgr.exe, and then select OK.
In IIS Manager, expand server name, expand Web sites, and then select the website that you want to change.
In the Features view, double-click Directory Browsing.
In the Actions pane, select Enable.
Method 2: Add a default document
To resolve this problem, follow these steps:
Start IIS Manager. To do it, select Start, select Run, type inetmgr.exe, and then select OK.
In IIS Manager, expand server name, expand Web sites, and then select the website that you want to change.
In the Features view, double-click Default Document.
In the Actions pane, select Enable.
In the File Name box, type the name of the default document, and then select OK.

2 IIS Flask sites on Windows Server - Only 1 runs

Windows Server DataCenter 2019
Python 3.7.6
I have 2 sites configured on IIS.
mysite1 port 9090: Runs using VSCode and entering URL in browser
Runs from VSCode
Enter URL in Browser: ###.###.###.###:9090
mysite2 port 9566: Only runs from VSCode
Runs from VScode.
ERROR 500. Enter URL in Browser: ###.###.###.###:9566
Also from IIS Manager menu option: Browse *:9566
HTTP Error 500.0 - Internal Server Error
C:\inetpub\wwwroot\Flask\mysite2\venv\Scripts\python.exe - The FastCGI process exited unexpectedly
Detailed Error Information:
Module
FastCgiModule
Notification
ExecuteRequestHandler
Handler
Python FastCGI
Error Code
0x00000067
Requested URL
http://localhost:9566/
Physical Path
C:\inetpub\wwwroot\Flask\mysite2
Logon Method
Anonymous
Logon User
Anonymous
The 2 sites are configured with different AppPools
2 web.config files
<configuration>
<system.webServer>
<handlers>
<remove name="FlaskHandler" />
<add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\inetpub\wwwroot\Flask\mysite1\venv\Scripts\python.exe|C:\inetpub\wwwroot\Flask\mysite1\venv\lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<add key="WSGI_HANDLER" value="app.app" /> <!-- {name_of_file}.{name_of_flask_app}-->
<add key="PYTHONPATH" value="C:\inetpub\wwwroot\Flask\mysite1" />
<add key="WSGI_LOG" value="C:\inetpub\wwwroot\Flask\mysite1\app.log" />
</appSettings>
</configuration>
<configuration>
<system.webServer>
<handlers>
<remove name="FlaskHandler" />
<add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\inetpub\wwwroot\Flask\mysite2\venv\Scripts\python.exe|C:\inetpub\wwwroot\Flask\mysite2\venv\lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<add key="WSGI_HANDLER" value="app.app" /> <!-- {name_of_file}.{name_of_flask_app}-->
<add key="PYTHONPATH" value="C:\inetpub\wwwroot\Flask\mysite2" />
<add key="WSGI_LOG" value="C:\inetpub\wwwroot\Flask\mysite1\app.log" />
</appSettings>
</configuration>
The same steps were used to create mysite1 and mysite2.
In IIS manager, I stopped mysite1 but mysite2 does not run using entering URL in a browser.
Help is appreciated 1
More Debugging
I turned on Failed Request Tracing
https://learn.microsoft.com/en-us/iis/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis
These are the Error and Warning traced log messags
94. FASTCGI_UNEXPECTED_EXIT
Error
95. SET_RESPONSE_ERROR_DESCRIPTION 22:01:34.515
Warning
ErrorDescription="C:\inetpub\wwwroot\Flask\mysite2\venv\Scripts\python.exe - The FastCGI process exited unexpectedly" 22:01:34.515
96. MODULE_SET_RESPONSE_ERROR_STATUS
Warning
ModuleName="FastCgiModule", Notification="EXECUTE_REQUEST_HANDLER", HttpStatus="500", HttpReason="Internal Server Error", HttpSubStatus="0", ErrorCode="The semaphore cannot be set again.
(0x67)", ConfigExceptionInfo=""
Debug Post: Python flask app on IIS not working on Windows Server 2019
I do not understand what running wfastcgi.py does but both mysite1 and mysite2 behave the same way.
The "working" site, runs and does not end
C:\inetpub\wwwroot\Flask\RESTAPI_mysite1\venv\Scripts\python.exe C:\inetpub\wwwroot\Flask\mysite1\venv\lib\site-packages\wfastcgi.py
The "non-working" site, runs and does not end
C:\inetpub\wwwroot\Flask\RESTAPI_mysite2\venv\Scripts\python.exe C:\inetpub\wwwroot\Flask\mysite2\venv\lib\site-packages\wfastcgi.py
Debug Post: Getting 500 Internal Server Error when setting up Python and Flask with FastCgiModule on Windows
The suggestions did not work for mysite2.
Help is appreciated 2
It is strange about the application pool. Maybe some special settings of site1 app pool are unknow. Even you create a new pool manually, those settings arenot configured in new pool.
Try to use appcmd to copy the site1 pool to new pool.(Stop site1 pool firstly)
Run command line as administrator.
CD C:\Windows\System32\inetsrv
appcmd.exe list apppool "site1 pool name" /config /xml > D:\AppPoolConfig.xml
appcmd.exe add apppool /name:new pool name /in < D:\AppPoolConfig.xml
Then start the new pool in IIS Manager. Make site2 work on it.

Deploying Django application with SQL Database to Azure

I've built a simple Django application on my local Windows machine that connects to a SQL Server hosted on Azure by leveraging the Django-Pyodbc-Azure back end. I'm able to connect to the database fine on my local machine and my app runs without issue.
However, I'm not in the process of deploying the application to Azure's app service and I'm running into problems. The deployment itself runs without issue, however the following error message shows up in my logs:
Traceback (most recent call last): File "/home/site/wwwroot/antenv3.6/lib/python3.6/site-packages/sql_server/pyodbc/base.py", line 15, in <module>
import pyodbc as Database
ImportError: libodbc.so.2: cannot open shared object file: No such file or directory
File "/home/site/wwwroot/antenv3.6/lib/python3.6/site-packages/sql_server/pyodbc/base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading pyodbc module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading pyodbc module: libodbc.so.2: cannot open shared object file: No such file or directory
My requirements.txt file looks as such:
Django==2.1.4
django-pyodbc-azure==2.1.0.0
pyodbc==4.0.25
pytz==2018.7
And again... this runs fine locally on my Windows machine. But I get this error when I deploy to Azure.
I suspect this has something to do with the Pyodbc backend not being installed correctly on Azure's LINUX based app service? Does anybody have experience resolving this?
I was running into this same issue with the pyodbc package when using the Linux version. I was using the Windows based web-app but had to rebuild from scratch and accidentally selected the Linux version.
Once switching back to the Windows version I used python 3.6 and followed these steps, (based on this blog for deploying a flask app, https://blogs.msdn.microsoft.com/pythonengineering/2016/08/04/upgrading-python-on-azure-app-service/):
Deploy a Django web-app to Azure
In the portal click on "Web App">"New"
Give the web app a name: <webappname>
Set the resource group to be the same as the database
Select the OS to be Windows
Click, deploy - This will take few minutes to deploy
Once deployed you can click on the URL https://<webappname>.azurewebsites.net to see a default azure web page
In your Django project go to settings.py and in the "ALLOWED_HOSTS" add ".azurewebsites.net".
In the Azure portal>webapp, go to Extensions and install python3.6 x64
In Portal > webapp > Application settings, select "Always on".
In settings.py set:
DEBUG = os.getenv('DJANGO_DEBUG') != 'FALSE'
also set other private variables as environment variables (these should then be added as key-value pairs (e.g. DJANGO_DEBUG = FALSE) in Portal>webapp>Application settings>Application settings.
Also, to connect to the SQL database set the database settings to be:
OPTIONS[driver] = 'SQL Server Native Client 11.0'
OPTIONS[MARS_Connection] = 'True'
Make sure you have the following files in the base directory of your django project:
ptvs_virtual_proxy.py
.SkipPythonDeployment
web.config make sure you have key="DJANGO_SETTINGS_MODULE" value "<django-project-name>.settings" (see below)
In your local project, Run pip freeze and put the contents into requirements.txt (see below)
Check that all migration files have been added to git by running git status
Commit and push the changes to your git repo
In the portal, in your new web-app go to "Deployment options"
"Choose Source" -> Follow the steps and click "Finish/Ok" to see the deployment progress and view the logs
Once deployment says "Success", Go to Kudu (http://<webappname>.scm.azurewebsites.net)>Powershell, and run D:\home\python364x64\python.exe -m pip install --upgrade -r D:\home\site\wwwroot\requirements.txt, This should hopefully be successful and only needs to be rerun when you update a package.
Then go back to "Deployment Center" and click on the logs button, and click redeploy, you may also need to restart the web-app to update the environment variables (go to webapp>overview>restart).
For static files, either commit all the admin files after running locally python manage.py collectstatic or you can setup static files like this, then run D:\home\python364x64\python.exe D:\home\site\wwwroot\manage.py collectstatic in Kudu)
web.config file:
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="<django-project-name>.wsgi.application"/>
<add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
<add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
<add key="PYTHONPATH" value="D:\home\site\wwwroot" />
<add key="DJANGO_SETTINGS_MODULE" value="<django-project-name>.settings" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<httpErrors errorMode="Detailed"></httpErrors>
<handlers>
<add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python364x64\python.exe|D:\home\python364x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
</handlers>
<rewrite>
<rules>
<rule name="Static Files" stopProcessing="true">
<conditions>
<add input="true" pattern="false" />
</conditions>
</rule>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
requirements.txt file:
cycler==0.10.0
Django==1.11.15
django-pyodbc-azure==1.11.15.0
djangorestframework==3.6.3
djangorestframework-jsonp==1.0.2
pyodbc==4.0.25
please go to the scm site of your web app, then try to manually install the modules which throw the error.
For detailed steps, please refer to this article.

Deploying two different Django Applications on Windows Server in IIS

I am deploying two different Django applications on Windows 2012 in IIS. My first application is running but I can't seem to run my second application.
My question is how do I configure my FastCGI Settings if I have two PYTHONPATH and two DJANGO_SETTINGS_MODULE?
Do I put a semicolon every after values? For example:
NAME: DJANGO_SETTINGS_MODULE
VALUE: mysettings.settings;myothersettings.settings
NAME: PYTHONPATH
VALUE: C:\PythonApps\firstapp;C:\PythonApps\secondapp
Step 1) Web Server's FastCGI Settings - in your web server under FastCGI Settings create an application for each site you will be running. If you are using a venv be sure to point to your python.exe and wfastcgi.py file within that venv. For isntance, I have one that points to:
"C:\Apps\.virtualenv\[enviroment-name]\python.exe|C:\Apps\.virtualenv\[enviroment-name]\Lib\site-packages\wfastcgi.py"
And one that points to:
"C:\Python37\pytohn.exe|C:\Python37\Lib\site-packages\wfastcgi.py"
Step 2) Website's Handler Mappings - for each handler mapping, The Module with be FastCgiModule and the settings should mirror the application settings you created in step one. So one site should have an executable of:
"C:\Apps\.virtualenv\[enviroment-name]\python.exe|C:\Apps\.virtualenv\[enviroment-name]\Lib\site-packages\wfastcgi.py"
The other should be:
"C:\Python37\pytohn.exe|C:\Python37\Lib\site-packages\wfastcgi.py"
Step 3) Web.Config File - In the root of your django app, save a file like the one below. The web server handler should coincide with the application setting you are using. Down in application settings you can define your WSGI_HANDLER, PYTHONPATH, and DJANGO_SETTINGS_MODULE.
https://pypi.org/project/wfastcgi/
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI"
path="*"
verb="*"
modules="FastCgiModule"
scriptProcessor="C:\python37\python.exe|C:\python37\Lib\site-packages\wfastcgi.py"
resourceType="Unspecified"
requireAccess="Script" />
</handlers>
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="core.wsgi.application" />
<add key="PYTHONPATH" value="C:\apps\django\dash" />
<!-- Optional settings -->
<add key="DJANGO_SETTINGS_MODULE" value="core.settings.production" />
</appSettings>
</configuration>