【问题标题】:ValueError: "django.core.wsgi.get_wsgi_application()" could not be importedValueError:“django.core.wsgi.get_wsgi_application()”无法导入
【发布时间】:2017-05-02 19:08:35
【问题描述】:

我在 web.config 文件中设置了所有路径,并在 IIS 中配置了所有内容(在 Windows Server 2012 R2 上)。完成后,我启动了服务器并访问了该网站。但是在这样做时,我收到了以下错误消息:

Error occurred while reading WSGI handler:

Traceback (most recent call last):
  File "C:\inetpub\wwwroot\djangoapp\wfastcgi.py", line 711, in main
    env, handler = read_wsgi_handler(response.physical_path)
  File "C:\inetpub\wwwroot\djangoapp\wfastcgi.py", line 568, in read_wsgi_handler
    return env, get_wsgi_handler(handler_name)
  File "C:\inetpub\wwwroot\djangoapp\wfastcgi.py", line 551, in get_wsgi_handler
    raise ValueError('"%s" could not be imported' % handler_name)
ValueError: "django.core.wsgi.get_wsgi_application()" could not be imported


StdOut: 

StdErr:

Web.config(文件):

 <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI"
path="*"
verb="*"
modules="FastCgiModule"
scriptProcessor="C:\Python34\python.exe|C:\inetpub\wwwroot\djangoapp\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="C:\Python34\python.exe" />
<add key="WSGI_RESTART_FILE_REGEX" value=".*((\.py)|(\.config))$" />
<add key="DJANGO_SETTINGS_MODULE" value="djangoapp.settings" />
</appSettings>
</configuration>

我不明白为什么会出现这个错误。有谁知道如何解决这个问题?

【问题讨论】:

    标签: django iis windows-server-2012-r2 wfastcgi


    【解决方案1】:

    这就是我们之间的区别。

    <add key="WSGI_HANDLER" value="django.core.handlers.wsgi.WSGIHandler()" />
    <add key="PYTHONPATH" value="[PATH_OF_DJANGOAPP]" />
    

    【讨论】:

      【解决方案2】:

      我在网上经常看到这个问题。您在这里遇到的问题是您的机器上有 2 个版本的 Python。确保为两个版本都安装了所有东西。例如 Python 3.4 版:py -m pip install django 和 Python 3.6 版:pip install django 当然取决于您的环境变量是如何设置的。请确保一切正常下载。另请注意,对于这两个版本,您还必须输入以下命令才能使其工作: 对于 3.6 版(以我为例):

      pip install --upgrade wheel
      pip install wfastcgi
      wfastcgi-enable
      

      对于 3.4 版(以我为例):

      py -m pip install --upgrade wheel
      py -m pip install wfastcgi
      wfastcgi-enable
      

      请注意,两个版本都有自己的 wfastcgi。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-15
        • 2021-08-01
        • 2018-12-28
        • 2021-11-20
        • 2020-01-21
        • 2019-01-12
        • 2020-11-15
        • 2019-06-04
        相关资源
        最近更新 更多