Azure Web 应用程序 - Python:无法打开文件“manage.py”:[Errno 0] 无错误

问题描述

我正在尝试使用 Azure DevOps 作为 Azure Web 应用程序部署我的 Django 应用程序。该应用程序已流水线化并构建到 Web 应用程序,但它不会运行。 当我尝试在诊断控制台中运行 py manage.py runserver 时,出现以下错误

D:\python34\python.exe: can't open file 'manage.py': [Errno 0] No error

有人知道可能是什么问题吗? 这是我尝试使用 Azure 部署的第一个项目,所以我的知识不是很好。 项目文件存储在服务器上的以下位置

D:\home\site\wwwroot\<applicationName>

我有时也会收到此错误

Window title cannot be longer than 1023 characters.

文件结构

wwwroot
--- 应用名称
------ api
------ 应用名称
------ .env
------ db.sqlite3 (空且未使用)
------ 管理.py
------ 需求.txt

尝试解决问题的方法

  1. 根据 Jason Pan 的想法在 Configuration -> Path Mappings -> Physical Path 中更改文件路径
  2. 添加一个 web.config 文件(在 wwwroot -> applicationname -> web.config添加)。配置文件粘贴在下面。这导致了以下错误The specified CGI application encountered an error and the server terminated the process.

Web.Config 文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
 <system.webServer>

  <handlers>
    <add name="httpPlatformHandler" path="*" verb="*"
               modules="httpPlatformHandler" resourceType="Unspecified"/>
  </handlers>

  <httpPlatform proce@R_404_6432@ath="D:\home\python364x64\python.exe" arguments="manage.py runserver %HTTP_PLATFORM_PORT%" requestTimeout="00:04:00" startupTimeLimit="120" startupRetryCount="3" stdoutLogEnabled="true">
    <environmentvariables>
     <environmentvariable name="PYTHONPATH" value="D:\home\site\wwwroot"/>
    </environmentvariables>
  </httpPlatform>

 </system.webServer>
</configuration>

感谢您的帮助。

解决方
在 Jason Pan 的大力帮助下,我设法将其设置为容器服务,并且该应用程序现在可以正常工作了!非常感谢杰森!

解决方法

最新

之前我们改变了路径,我们需要修改回来。

enter image description here

步骤 1. 添加扩展。

enter image description here

步骤 2. 添加 web.config。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="D:\home\python364x64\python.exe"
                  arguments="D:\home\site\wwwroot\manage.py runserver %HTTP_PLATFORM_PORT%"
                  stdoutLogEnabled="true"
                  stdoutLogFile="D:\home\LogFiles\python.log"
                  startupTimeLimit="60"
                  processesPerApplication="16">
      <environmentVariables>
        <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>

步骤 3. 确保 wwwroot 文件夹中的目录结构与我的相同。

enter image description here

步骤 4. 在 pip install python-decouple 中运行命令 python364x64

enter image description here

第 5 步。然后您的应用就可以了。如果还有问题,可以像我一样排查。

enter image description here

测试结果。

在本地。

enter image description here

部署后。

enter image description here

enter image description here


您的目录结构应如下所示。它会正常工作。

wwwroot
--- api
--- 应用名称
--- .env
--- db.sqlite3(空且未使用)
--- 管理.py
--- 要求.txt

为了验证我的猜测,你可以在门户中这样测试。

enter image description here

然后重新启动您的网络应用程序,如果它有效,它也可以是一个解决方案。之前出现这个问题的原因是添加了文件夹applicationname。