IIS如何部署python django项目

1. 安装 wfastcgi, pip install wfastcgi。

2. 配置iis。点击iis根, 右侧 主页 点击 "FastCGI设置" -> 最右上方 选择 "添加应用程序" 
  完整路径:D:\python\\venv\Scripts\python.exe
  参数:D:\python\Lib\site-packages\wfastcgi.py

3. 点击 你的网站。 新建web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <!-- appSettings 必须在这里,与 system.webServer 同级 -->
    <appSettings>
        <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
        <add key="PYTHONPATH" value="D:\pythonwebsite" />
        <add key="DJANGO_SETTINGS_MODULE" value="website1.settings" />
        <!-- 可选:启用日志记录 -->
        <add key="WSGI_LOG" value="c:\logs\wfastcgi.log" />
    </appSettings>

    <system.webServer>
        <handlers>

            <!-- 添加 Python FastCGI 处理程序 -->
            <add name="Python FastCGI"
                 path="*"
                 verb="*"
                 modules="FastCgiModule"
                 scriptProcessor="D:\python\venv\Scripts\python.exe|D:\python\venv\Lib\site-packages\wfastcgi.py"
                 resourceType="Unspecified" />
        </handlers>

        <!-- 安全设置 -->
        <security>
            <requestFiltering>
                <hiddenSegments>
                    <remove segment="bin" />
                </hiddenSegments>
            </requestFiltering>
        </security>
    </system.webServer>
</configuration>

  

还不行就用cmd试试:
cd D:\python\Scripts
d:
activate
wfastcgi-enable

posted @ 2026-01-08 14:22  iDEAAM  阅读(15)  评论(0)    收藏  举报