【发布时间】:2018-02-05 03:09:00
【问题描述】:
我在 Visual Studio 2017 中使用 Django 制作了一个简单的应用程序,利用 Visual Studio 中的默认模板(文件 - 新建 - 项目 - python - django Web 应用程序)。我已经通过 azure 门户安装了 django PTVS,并添加了一个自定义 python 扩展。该应用程序在本地正常运行,但在我通过 Visual Studio 将其部署到 Azure 后,我只能访问显示的页面:
'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>
更新:
我设法让它工作,问题是它仍然继续使用带有 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>
【问题讨论】:
-
嗨,有什么更新吗?
-
@JayGong 对不起,我以为我已经发布了结果。所以是的,我设法让它工作,问题似乎是它一直在使用带有 python 3.4 的环境,因此我更改了应用程序设置以使用更新的 python 版本。
-
好的。感谢您的回复。我在回答中总结了这个问题。您可以在论坛上标记答案以供其他人参考。
标签: python django visual-studio azure