I'll keep a reminder of how I ran the Django tutorial on IIS on Windows 10.
Creating your first Django app, part 1 Host Django on Windows7 + IIS + virtualenv + wfastcgi Running Python (Django) on Windows + IIS HTTP error when opening IIS web page 500.19
Download the installer from the Official Site. When installing, please install for all users. If it is an individual user installation, it cannot be used by IIS users and cannot be operated.
I want to use PostgreSQL, so I will install it.
Download the installer from the Official Site. This time I installed version 13 of Windows x86-64.
From Control Panel> Programs> Enable or Disable Windows Features Enable Internet Information Services.
Computer Management> Services and Applications If the Internet information service has been added, it has been enabled.
We will create a "web" directory under C: \ Users \ username and work there.
command prompt
C:\Users\username> mkdir web
Install virtualenv
command prompt
C:\Users\username\web> pip install virtualenv
Creating a virtual environment (env)
command prompt
C:\Users\username\web> virtualenv env
Enable virtual environment
command prompt
C:\Users\username\web> env\Scripts\activate
Django installation
command prompt
(env) C:\Users\username\web> pip install Django
wfastcgi installation
command prompt
(env) C:\Users\username\web> pip install wfastcgi
Installation of psycopg2
command prompt
(env) C:\Users\username\web> pip install psycopg2
The result of pip list is below.
command prompt
(env) C:\Users\username\web>pip list
Package Version
---------- -------
asgiref 3.2.10
Django 3.1.1
pip 20.2.3
psycopg2 2.8.6
pytz 2020.1
setuptools 49.6.0
sqlparse 0.3.1
wfastcgi 3.0.0
wheel 0.35.1
Follow the Django tutorial to create your project.
command prompt
(env) C:\Users\username\web> django-admin startproject mysite
Check if it works locally
command prompt
(env) C:\Users\username\web>mysite> python manage.py runserver
Go to http://127.0.0.1:8000/ and when the following page is displayed, it's OK.
Add a new site. From Computer Management> Internet Information Services Set the physical path etc. in Site> Add Website.
The physical path sets the folder for your Django project (parent folder, such as manage.py).
Set from Handler Mappings> Add Script Map. The executable file specifies python.exe in the env environment.
Unlock to use wfastcgi
(env) C:\Users\username\web\mysite>%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/handlers
Configuration path"MACHINE/WEBROOT/APPHOST"Section"system.webServer/handlers"Unlocked.
Run wfastcgi enable
(env) C:\Users\username\web\mysite>wfastcgi-enable
Configure configuration changes Commit path"MACHINE/WEBROOT/APPHOST"of"MACHINE/WEBROOT/APPHOST"Section"system.webServer/fastCgi"Applied to
"c:\users\username\web\env\scripts\python.exe|c:\users\username\web\env\lib\site-packages\wfastcgi.py" can now be used as a FastCGI script processor
Create web.config under the Django project (same directory as manage.py). Set the value of scriptProcessor to the value displayed by wfastcgi-enable.
web.config
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
<add key="PYTHONPATH" value="C:\Users\username\web" />
<add key="DJANGO_SETTINGS_MODULE" value="mysite.settings" />
</appSettings>
<system.webServer>
<handlers>
<add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="c:\users\username\web\env\scripts\python.exe|c:\users\username\web\env\lib\site-packages\wfastcgi.py" resourceType="Unspecified" />
</handlers>
</system.webServer>
</configuration>
Computer Management> Internet Information Services Edit the permissions from My Site (newly created site). Add user [Computer Name \ IIS_IUSRS] on the Security tab
Also, in File Explorer, right-click on the C: \ Users \ username \ web env folder> Properties Also add a user with [Computer name \ IIS_IUSRS].
Go to Computer Management> Internet Information Services, select My Site, browse the website and the rocket flies, then the Django site is running.
If you get a 0x800700005 error or a 0x8007010b error as shown below, Please check if the file access permission and the Python.exe path set in the handler mapping are appropriate.
Cause: Occurs when the site directory does not have access to the computer name \ IIS_IUSRS Solution: Add permissions for computer name \ IIS_IUSRS
Cause: Occurs when you do not have access to the computer name \ IIS_IUSRS in the Python.exe directory you are using. Solution: Add permissions for computer name \ IIS_IUSRS
Next time I will write the procedure to change the database to PostgreSQL: wave:
Recommended Posts