如何在Azure上部署Django应用程序?

时间:2017-09-15 17:36:23

标签: django python-3.x azure-web-sites

我之前发过但未收到回复。 我有一个在VS2017中开发的Django Web应用程序。我发布了它但收到服务器错误。你能告诉我如何配置我的web.config文件以便它可以工作吗?目前是:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
    <add key="WSGI_HANDLER" value="app.wsgi_app"/>
    <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
  </appSettings>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\Python361x64\python.exe|D:\home\Python361x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
    </handlers>
  </system.webServer>
</configuration>

但我收到服务器错误,Python日志文件说:

D:\ home \ Python361x64 \ python.exe:无法打开文件'D:\ home \ site \ wwwroot \ runserver.py':[Errno 2]没有这样的文件或目录

我将不胜感激。

1 个答案:

答案 0 :(得分:0)

您需要在提及here的KUDU上将static files url configuration添加到web.config文件。

我尝试将自己的Django项目部署到azure并使用您的web.config文件,并且效果很好。

您可以参考以下web.config配置:

<configuration>
  <appSettings>
    <add key="WSGI_HANDLER" value="DjangoWebProject1.wsgi.application"/>
    <add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
    <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
  </appSettings>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python362x86\python.exe|D:\home\python362x86\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
    </handlers>
    <rewrite>
      <rules>
        <rule name="Static Files" stopProcessing="true">
          <conditions>
            <add input="true" pattern="false" />
          </conditions>
        </rule>
        <rule name="Configure Python" stopProcessing="true">
          <match url="(.*)" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

<强> 注意

请确保

path属性的值

<add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python362x86\python.exe|D:\home\python362x86\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>

url属性的值相同
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />