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 :