Search code examples
pythondjangoazuremanage.py

Azure Web App - Python: can't open file 'manage.py': [Errno 0] No error


I am trying to deploy my Django application with Azure DevOps as a Azure Web App. The application is pipelined and build to the web app but it will not run. When I am trying to run py manage.py runserver in the Diagnostic Console i get the error below:

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

Does anyone have a clue on what the issue might be? This is the first project I am trying to deploy with Azure so my knownledge is not very good. The project files are stored on the following location on the server

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

I am sometimes getting this error as well:

Window title cannot be longer than 1023 characters.

Filestructure

wwwroot
--- applicationname
------ api
------ applicationname
------ .env
------ db.sqlite3 (empty and not in use)
------ manage.py
------ requirements.txt

Things that have been tried to solved the issue

  1. Changing the filepath in Configuration -> Path Mappings -> Physical Path after an idea from Jason Pan
  2. Add a web.config file (Added in wwwroot -> applicationname -> web.config). The Config file is pasted below. This resulted in the following error: The specified CGI application encountered an error and the server terminated the process.

Web.Config file:

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

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

  <httpPlatform processPath="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>

Thank you for your help.

SOLUTION
After huge help from Jason Pan i manage to set it up as a Container Service instead and the app is now working as it should! Thank you very much Jason!


Solution

  • Newest

    Previous we change path, we need to modify it back.

    enter image description here

    Step 1. Add Extensions.

    enter image description here

    Step 2. Add 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>
    

    Step 3. Make sure that the directory structure in your wwwroot folder is the same as mine.

    enter image description here

    Step 4. Run command pip install python-decouple in python364x64.

    enter image description here

    Step 5. Then your app will be ok. If also have issues, you can troubleshoot like me.

    enter image description here

    Test Result.

    In local.

    enter image description here

    After deployed.

    enter image description here

    enter image description here


    Your directory structure should look like this. And it will work fine.

    wwwroot
    --- api
    --- applicationname
    --- .env
    --- db.sqlite3 (empty and not in use)
    --- manage.py
    --- requirements.txt

    In order to verify my guess, you can test like this in the portal.

    enter image description here

    Then restart your web app, if it works, it also can be a solution. The reason for this problem before was that the folder applicationname was added.