2017-08-27 48 views
1

我使用Visual Studio(文件 - 新建 - 项目 - python - django web应用程序)中的默认模板在Visual Studio 2017中制作了一个简单的应用程序。我已经通过azure门户安装了django PTVS并添加了一个自定义的python扩展。该应用程序运行正常在本地,而是当我部署它通过Visual Studio来Azure的,我只能访问显示页面:将Django应用程序部署到Azure VS2017 - 自定义python

'Your App Service app has been created.'

我读过几个职位(Deploy a simple VS2017 Django app to Azure - server error),并遵循以下教程: https://docs.microsoft.com/en-us/visualstudio/python/managing-python-on-azure-app-service

我的web.config看起来如下:

<?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:

我设法让它工作,问题是它仍然继续使用python 3.4的env,并且似乎有一个软件包依赖项需要较新版本的python,因此我按照以下方式更改了应用程序设置。

<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> 
+0

嗨,任何更新? –

+0

@JayGong对不起,我以为我已经发布了结果。所以是的,我设法得到它的工作,问题似乎是它保持使用python 3.4 env我因此改变了应用程序设置使用更新的python版本。 – Galdar

+0

好的。谢谢你的回复。我在回答中总结了这个问题。您可以在论坛上标记答案供他人参考。 –

回答

0

我试图重现您的问题,但失败了。我的Django应用创建了由VS2017部署到Azure WebApps的&,它可以工作。有一些类似的SO线程与您的问题相同。

  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

你可以按照上面的线程来再试一次。另外,您可以参考the official tutorial for Django来创建您的django应用并将其部署到Azure,然后将您的web.config更改为使用Python 3.6.1扩展。

以下是我的web.config文件的内容,如下所示。

<?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> 

正如总之,问题是使用使用python的ENV 3.4.Just将其更改为Python解释器的新版本的项目保留。

web.config设置:

<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> 

希望它能帮助。

相关问题