在Windows Azure上配置Python 3.4和Django

1 投票
1 回答
1530 浏览
提问于 2025-04-18 11:38

我在Windows Azure上有一个网站,管理员控制台里设置了Python 3.4。这里是web.config的内容:

<configuration>
<appSettings>
    <add key="pythonpath" value="D:\home\site\wwwroot\mysite;D:\home\site\wwwroot\site-packages" />
    <add key="WSGI_HANDLER" value="django.core.handlers.wsgi.WSGIHandler()" />
    <add key="DJANGO_SETTINGS_MODULE" value="core.settings" />   
</appSettings>
<system.webServer>
    <handlers>
        <add name="Python_FastCGI"
            path="handler.fcgi"
            verb="*"
            modules="FastCgiModule"
            scriptProcessor="D:\Python34\python.exe|D:\Python34\Scripts\wfastcgi.py"
            resourceType="Either"
            requireAccess="Script" />
    </handlers>
    <rewrite>
        <rules>
            <rule name="Django Application" stopProcessing="true">
                <match url="(.*)" ignoreCase="false" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                </conditions>
                <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

当fastCGI配置中的scriptProcessor属性设置为使用d:\Python27时,一切都运行得很好,但设置为d:\Python34时就不行了。我已经用Python 2.7确认过,服务器上确实存在D:\Python34\python.exe和D:\Python34\Scripts\wfastcgi.py这两个文件。

编辑:

为了更清楚一点,服务器返回了

The page cannot be displayed because an internal server error has occurred.

查看详细日志时,显示了一个通用的500内部服务器错误信息,指向FastCgiModule。

1 个回答

1

你的 web.config 文件看起来没问题。(不过你可能想把 appendQueryString 设置为 "true")。

在 Azure 门户里开启日志记录,并在你的 Django 项目中临时设置 DEBUG=True。然后去 D:\home\LogFiles\ 看看那个通用的 500 错误背后发生了什么。

出现这个通用的 500 错误说明你正在运行 Django。你也可以去 https://.scm.azurewebsites.net 的进程查看器看看 Python 进程是否在运行。

撰写回答