[英]Deploy Django app to Azure VS2017 - custom python
我使用Visual Studio 2017中的默認模板(文件-新建-項目-python-django Web應用程序)在Django中使用Visual Studio 2017創建了一個簡單的應用程序。 我已經通過azure門戶網站安裝了django PTVS,並添加了一個自定義python擴展名。 該應用程序在本地正常運行,但是在通過Visual Studio將其部署到Azure之后,我只能訪問顯示以下頁面:
'Your App Service app has been created.'
我已經閱讀了幾篇文章( 將簡單的VS2017 Django應用程序部署到Azure-服務器錯誤 ),並遵循了以下教程: https : //docs.microsoft.com/zh-cn/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>
更新:
我設法使其正常運行,問題在於它仍然繼續將env與python 3.4一起使用,並且似乎存在依賴於軟件包的依賴關系,需要新版本的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>
我試圖重現您的問題,但失敗了。 我的Django應用由VS2017創建並部署到Azure WebApp,並且可以運行。 有一些類似的SO線程與您有相同的問題。
您可以按照上述主題重試。 您也可以參考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 3.4使用env,只需將其更改為新版本的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>
希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.