gpt4 book ai didi

python - 将 Django 应用程序部署到 Azure VS2017 - 自定义 python

转载 作者:行者123 更新时间:2023-12-03 04:23:51 24 4
gpt4 key购买 nike

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

“您的应用服务应用已创建。”

我已经阅读了几篇文章 ( Deploy a simple VS2017 Django app to Azure - server error ) 并遵循了以下教程: https://learn.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>

更新:

我设法让它工作,问题是它仍然继续使用 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 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 3.4 的环境。只需将其更改为新版本的 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>

希望有帮助。

关于python - 将 Django 应用程序部署到 Azure VS2017 - 自定义 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45908967/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com