Deploying Django App usig IIS Windows Server and MSSQL
Deploying Django App usig IIS Windows Server and MSSQL
Feb. 8, 2024, 10:09 a.m.
Server, Blog,
0 Comments
In this tutorial I will be deploying a Single Page App to Windows Server IIS and MSSQL for the Database. This is an actual project and I will be deploying it to our company. The idea is that, we are using a system called ServiceNow and in the even that the ServiceNow is down, using this SPA, we are able to lodge a request or an incident and once the ServiceNow is back online, we will create a PowerShell script to upload all data a back to the ServiceNow. Im assuming your PC has already installed Python.
Steps to follow:
- Setting up Windows IIS - Navigate to Server Manager
- Make sure to Tick Web Server (IIS) and in the IIS Role Services Check the CGI
3. Install Python, and once installed Open CMD and install wfastcgi by using “pip install wfastcgi”
4. Enable wfastcgi by typing “wfastcgi-enable”, take note on the python path and wfastcgi path (e.g, c:\python312\python.exe and c:\python312\lib\site-packages\wfastcgi.py)
5. Go to FASTCGI Settings -> Add Apllications and put the above path
6. Save you Django app to the C:\inetpub\wwwroot – you can use Git Version Control or manually copy
7. Check the Properties of the folder and Add Full Control
9. Go to Site -> Add Website and complete the Form
10. Make sure that the system.webServer/handlers is set to Unlock
11. In your root directory of your Django app, create a web.config file and adjust/change the names
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
<!-- Your Django path -->
<add key="PYTHONPATH" value="C:\inetpub\wwwroot\snowmaintenance_app" />
<!-- Your Django settings module -->
<add key="DJANGO_SETTINGS_MODULE" value="snowmaintenance.settings" />
</appSettings>
<system.webServer>
<handlers>
<add name="snowmaintenance_app" path="*" verb="*" modules="FastCgiModule" scriptProcessor="c:\python312\python.exe|c:\python312\lib\site-packages\wfastcgi.py" resourceType="Unspecified" />
</handlers>
</system.webServer>
</location>
<system.web>
<identity impersonate="true" />
</system.web>
</configuration>
12. Go back to your Django application and do the database migration and setting up of the database to MSSQL
13. Install venv -> python3 -m ./venv – this will create a venv file
14. Activate .\venv\Script\activate
15. Install dependencies -> pip install -r requirements.txt – if it doesn’t work manual add them using pip, be sure to include pip install mssql-django this will install the driver for mssql and register mssql on the INSTALLED_APPS
16. Copy the settings and adjust name and pword
DATABASES = {
'default': {
'ENGINE': 'mssql',
'NAME': 'snow_db',
'USER': 'name',
'PASSWORD': password',
'HOST': 'localhost',
'PORT':'1433',
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
}
},
}
17. Configure the Database by running
18. Python manage.py makemigrations and python manage.py migrate
19. Double check if it writes data into database
20. Now test you app – Congratulation!!
For Full Video: Click Here!
0 Comments
No Comments Yet!
© TopITSolutions. All Rights Reserved.