1

I've made a simple app with Django in Visual Studio 2017, utilizing the default template in Visual Studio (file - new - project - python - django web application). I've installed django PTVS through the azure portal and added a custom python extension. The app runs properly locally, but after i deploy it to Azure via Visual Studio, i can only access the page that shows:

'Your App Service app has been created.'

I've read several posts (Deploy a simple VS2017 Django app to Azure - server error) and followed the following tutorials: https://learn.microsoft.com/en-us/visualstudio/python/managing-python-on-azure-app-service

My web.config looks as follows:

<?xml version="1.0"?>
<configuration>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="Python27_via_FastCGI" />
      <remove name="Python34_via_FastCGI" />
      <add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python361x64\python.exe|D:\home\python361x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
    </handlers>
  </system.webServer>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <appSettings>
    <add key="PYTHONPATH" value="%SystemDrive%\home\site\wwwroot" />
    <add key="WSGI_HANDLER" value="DjangoWebProject2.wsgi.application()"/>
    <add key="DJANGO_SETTINGS_MODULE" value="app.settings" />
  </appSettings>
</configuration>

UPDATE:

I managed to get it working, the problem was that it still kept using the env with python 3.4 and there seemed to be a package dependency that required a newer version of python I therefore changed the app settings as follows.

<configuration>
  <appSettings>
    <add key="WSGI_HANDLER" value="myApp.wsgi.application"/>
    <add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
    <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
    <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
    <add key="DJANGO_SETTINGS_MODULE" value="myApp.settings" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <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>
Galdar
  • 13
  • 4
  • Hi,any updates ? – Jay Gong Jan 23 '18 at 09:07
  • @JayGong Sorry, I thought I already posted the results. So yes I managed to get it working, the problem seemed to be that it kept using the env with python 3.4 I therefore changed the app settings to use a newer python version. – Galdar Jan 24 '18 at 09:08
  • Ok.Thanks for your replying.I summarized the issue in my answer. You could mark the answer for others' reference on the forum. – Jay Gong Jan 24 '18 at 09:12

1 Answers1

0

I tried to reproduce your issue, but failed. My Django app created & deployed by VS2017 to Azure WebApps and it works. There are some similar SO threads which have the same issue with yours.

  1. Only getting Your App Service app has been created - after deploying to azure
  2. Django web app deploy in Azure via Visual Studio 2017

You can follow the above threads to try again. Also you can refer to the official tutorial for Django to create and deploy your django app to Azure, then to change your web.config to use the Python 3.6.1 extension.

Here is the content of my web.config file as below.

<?xml version="1.0"?>
<!-- Generated web.config for Microsoft Azure. Remove this comment to prevent
     modifications being overwritten when publishing the project.
-->
<configuration>
  <system.diagnostics>
    <trace>
      <listeners>
        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
          <filter type="" />
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
  <appSettings>
    <add key="WSGI_ALT_VIRTUALENV_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
    <add key="WSGI_ALT_VIRTUALENV_ACTIVATE_THIS" value="D:\home\site\wwwroot\env\Scripts\activate_this.py" />
    <add key="WSGI_HANDLER" value="ptvs_virtualenv_proxy.get_virtualenv_handler()" />
    <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
    <add key="DJANGO_SETTINGS_MODULE" value="JayGongDjango.settings" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python361x64\python.exe|D:\home\python361x64\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>

Just as summary , the issue is the project kept using the env with python 3.4.Just change it to the new version of python interpreter.

web.config settings:

<appSettings> 
  <add key="WSGI_HANDLER" value="myApp.wsgi.application"/> 
  <add key="PYTHONPATH" value="D:\home\site\wwwroot"/> 
  <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/> 
  <add key="PYTHONPATH" value="D:\home\site\wwwroot" /> 
  <add key="DJANGO_SETTINGS_MODULE" value="myApp.settings" /> 
</appSettings>

Hope it helps.

Jay Gong
  • 23,163
  • 2
  • 27
  • 32