(1)打开『服务器管理器』
(2)选择『添加角色功能』
(3)『服务器选择』-> 『从服务器池中选择服务器』-> 『下一步』
(4)『服务器角色』-> 勾选『Web 服务器(IIS)』-> 『下一步』
(5)『安装』
(1)打开『服务器管理器』
(2)选择『添加角色功能』
(3)『服务器角色』-> 『Web服务器(IIS)』-> 『应用程序开发』-> 『CGI』-> 『下一步』
(4)『安装』
pip install wfastcgi
启动 wfastcgi:wfastcgi-enable
保存路径,待用:c:\workprograms\python\python38\python.exe|c:\workprograms\python\python38\lib\site-packages\wfastcgi.py
pip install requirements.txt
『服务器管理器』-> 『IIS』-> 选择服务器,右键选择『Internet Information Services(IIS)管理器』
网站名称:名称
物理路径:项目所在路径
在项目跟目录添加 web.config 配置文件。
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers> <add name="DjangoWebHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="(保存路径)" resourceType="Unspecified" /> <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="(保存路径)" resourceType="Unspecified" requireAccess="Script" /> </handlers> </system.webServer> <appSettings> <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" /> <add key="PYTHONPATH" value="(Path to Django Project)" /> <add key="DJANGO_SETTINGS_MODULE" value="(DjangoProkect).settings" /> </appSettings> </configuration>
别名:static
物理路径:项目路径\static
在 static 里添加配置文件:web.config
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <!-- this configuration overrides the FastCGI handler to let IIS serve the static files --> <handlers> <clear/> <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" /> </handlers> </system.webServer> </configuration>
在 settings.py 里添加:
STATIC_ROOT = os.path.join(BASE_DIR, ‘static‘)
CMD下运行以下命令:
python manage.py collectstatic
出现这样的情况是因为IIS7之后的版本都采用了更安全的 web.config 管理机制,默认情况下会锁住配置项不允许更改。我们把它解锁了就OK。
打开CMD,在里面依次输入下面两个命令:
%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/handlers
%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/modules
选择『网站』-> 『处理程序映射』
-> 『添加模块映射』
请求路径:*
模块:FastCgiModule
可执行文件:(保存路径)
名称:DjangoWebHandler
-> 『请求限制』:取消勾选。
『FastCGI设置』->
鼠标双击选择 ->
添加『环境变量』:
1. Name: WSGI_HANDLER
Value:django.core.wsgi.get_wsgi_application()
2. Name:PYTHONPATH
Value:(项目目录)
3. Name:DJANGO_SETTINGS_MODULE
Value:(项目名称.settings)
原文:https://www.cnblogs.com/aiMiku/p/12613714.html