1、安装wfastcgi

whL文件下载:https://files.cnblogs.com/files/blogs/693718/mod_wsgi.zip?t=1725605761&download=true
pip install wfastcgi
#启动
wfastcgi-enable
#如果启动报错,请先用下面的命令停止服务,再启动
#停止
wfastcgi-disable
(env) D:\Document\Document\apps\RobotManSys\env\Scripts>wfastcgi-enable
已经在配置提交路径“MACHINE/WEBROOT/APPHOST”向“MACHINE/WEBROOT/APPHOST”的“system.webServer/fastCgi”节应用了配置更改
"D:\Document\Document\apps\XXX\env\Scripts\python.exe|D:\Document\Document\apps\XXX\env\lib\site-packages\wfastcgi.py" can now be used as a FastCGI script processor

2、根目录下新增web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\Document\Document\apps\XXX\env\Scripts\python.exe|D:\Document\Document\apps\XXX\env\lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
    </system.webServer>
    <appSettings>
        <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
        <add key="PYTHONPATH" value="D:\Document\Document\apps\XXX" />
        <add key="DJANGO_SETTINGS_MODULE" value="XXX.settings.develop" />
    </appSettings>
</configuration>

3、在IIS里添加项目网站

4、网站目录下新增虚拟目录(静态文件)

目录下新增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>



问题:

1、HTTP 错误 500.19 Internal Server Error

出现这样的情况是因为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

#提示:如果使用上面的命令提示%windir%载入出错,请把%windir% 修改为 C:\windows

C:\windows\system32\inetsrv\appcmd unlock config -section:system.webServer/handlers

C:\windows\system32\inetsrv\appcmd unlock config -section:system.webServer/modules


(env) D:\Document\Document\apps\RobotManSys\env\Scripts>%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/handlers
在配置路径“MACHINE/WEBROOT/APPHOST”解除了“system.webServer/handlers”节的锁定。

(env) D:\Document\Document\apps\RobotManSys\env\Scripts>%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/modules
在配置路径“MACHINE/WEBROOT/APPHOST”解除了“system.webServer/modules”节的锁定。


2、HTTP 错误 500.21 - Internal Server Error

处理程序“Python FastCGI”在其模块列表中有一个错误模块“FastCgiModule”

无法在<fastCGI>应用程序配置中找到<handler> scriptProcessor


AttributeError: 'Settings' object has no attribute 'ROOT_URLCONF'


3、iis django admin  静态文件无法显示

    首先检查mysite/settings.py要有以下配置:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')

    urls.py 文件配置信息

from django.contrib import admin
from django.conf.urls import url,include
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
    url(r'^admin/',admin.site.urls),
 ] + static(settings.STATIC_URL,document_root = settings.STATIC_ROOT)

    使用命令导出相关静态文件,

    在mysite里创建static目录,执行python manage.py collectstatic
    会自动把python里site-packages/django/contrib/admin/static/admin下的文件复制到static文件夹下,也可自己找到文件路径进行手动复制)

XXX
posted on   Old-Kang  阅读(35)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
· 全程使用 AI 从 0 到 1 写了个小工具



点击右上角即可分享
微信分享提示