将简单的VS2017 Django应用程序部署到Azure-服务器错误 [英] Deploy a simple VS2017 Django app to Azure - server error

查看:95
本文介绍了将简单的VS2017 Django应用程序部署到Azure-服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用VS2017 Preview(包括用于Visual Studio的Python工具)创建Django Web应用程序,并将生成的应用程序部署到Azure(我目前处于30天试用期,以评估Azure)

I've been trying to create a Django web app using VS2017 Preview (which includes Python tools for Visual Studio), and deploy the resulting app to Azure (I'm currently on the 30-day trial period to evaluate Azure).

我已完成以下操作:

  • 启动VS2017,使用"Django Web Project"模板创建一个新项目.这样会创建一个带有bootstrap模板的Django网页-简单,并且在本地一切正常.

  • Start VS2017, create a new project with the "Django Web Project" template. This creates a Django webpage with the bootstrap template - simple, and everything works well locally.

在VS中,转到连接的服务=>发布",选择"Microsft Azure应用服务",创建一个新的应用服务和一个应用计划.实例创建成功.

In VS, go to Connected Services => Publish, select "Microsft Azure App Service", create a new App Service an an App Plan. The instances are created successfully.

单击发布"以通过VS WebDeploy发布.一切在控制台中看起来都不错,并在末尾显示Publish: 1 succeeded, 0 failed, 0 skipped.

Click "Publish" to publish via VS WebDeploy. Everything looks good in the console and it says Publish: 1 succeeded, 0 failed, 0 skipped at the end.

这将显示标准的Azure欢迎页面hostingstart.html,而不显示Django页面.删除该html文件后,只有一个The page cannot be displayed because an internal server error has occurred..我已经尝试了各种方法:转到portal.azure.com的应用程序设置",将Python版本从关闭"设置为"3.4"(实际上,我希望使用3.5,这是MS教程之一使用的-但是任何方法都可以)现在)-然后只显示hostingstart-python.html,仍然没有Django.我尝试通过VS中的添加=>新项=> Azure web.config(FastCGI)"添加默认的web.config.我尝试使用各种值WSGI_HANDLER(例如django.core.handlers.wsgi.WSGIHandler())和DJANGO_SETTINGS_MODULE(例如mydjangopage.settings)编辑该web.config,并尝试在"requests.txt"中添加"wfastcgi",等等.服务器错误.

This results in the standard Azure Welcome-start-page hostingstart.html showing, not the Django page. Once I remove that html file, there's only a The page cannot be displayed because an internal server error has occurred.. I've tried various things: Going to portal.azure.com "Application Settings", setting Python version from "Off" to "3.4" (I'd like 3.5 in fact, which one of MS's tutorial uses - but any will do for now) - then there's just a hostingstart-python.html showing, still no Django. I've tried adding a default web.config via "Add => New Item => Azure web.config (FastCGI)" in VS. I've tried editing that web.config with various values of WSGI_HANDLER (e.g. django.core.handlers.wsgi.WSGIHandler()) and DJANGO_SETTINGS_MODULE (e.g. mydjangopage.settings), I tried adding "wfastcgi" to requirements.txt, etc. Always just getting a server error.

我已经尝试这样做了几个小时,并且已经阅读了Microsoft,他们的博客和网络上所有可能的Deployment帮助页面.所有信息似乎都已过时,缺少信息,或者无法正常工作.在这一点上,我感到非常失望,并准备放弃.它不是应该这么简单吗?在VS中创建一个新项目,点击发布",它应该可以工作吗? (绝对不是,我从头开始多次重启并尝试了很多事情.)

I have been trying to do this for several hours now and I've read every possible Deployment help page from Microsoft, their blogs, and the web. All the information seems outdated, having missing pieces of information, or is just not working. At this point I'm quite disappointed and ready to give up. Isn't it supposed to be so simple? Create a new project in VS, hit "Publish", and it's supposed to work? (It's definitely not, I restarted from scratch multiple times and tried so many things.)

推荐答案

  1. 在Azure上创建WebApp(请勿在应用程序设置"中启用python!)

  1. Create a WebApp on Azure (Do not enable python in Application Settings !)

从部署选项中选择local git repository: 从properties复制git网址:

From deployment option select local git repository: From properties copy the git url:

https://github复制virtualenv_proxy.py文件. com/Azure-Samples/python-docs-hello-world 到您的文件夹中.

Copy virtualenv_proxy.py file from https://github.com/Azure-Samples/python-docs-hello-world into your folder.

创建文件runtime.txt并将python-3.4写入文件.

Create a file runtime.txt and write python-3.4 into it.

创建包含内容的文件web.3.4.config:

<configuration>
  <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\python.exe" />
    <add key="pythonpath" value="%SystemDrive%\home\site\wwwroot" />
    <add key="WSGI_HANDLER" value="virtualenv_proxy.get_venv_handler()" />
    <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
    <add key="DJANGO_SETTINGS_MODULE" value="myModule.settings" />
  </appSettings>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <add name="Python FastCGI" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\Python34\python.exe|D:\Python34\Scripts\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_SETTINGS_MODULE的值,将myModule替换为模块名称.如果创建了Web应用程序,则所有的设置和路径都应该完全相同.

The only settings you need to change here is the value for DJANGO_SETTINGS_MODULE, replace myModule with your module name. All the over settings and paths should be exactly the same if you created an Web App.

  1. 将所有内容推送到您在第1点获得的git url,Azure将检测并设置Python 3.4并安装requirements.txt中的所有程序包. 在那之后,一切都应该工作.如果不是,请使用ftp连接并查看\LogFiles\wfastcgi.log中的错误.
  1. Push everything to the git url you got at point 1, Azure will detect and set up Python 3.4 and install all packages from requirements.txt. After that everything should work. If not, connect using ftp and look into \LogFiles\wfastcgi.log for the error.

这篇关于将简单的VS2017 Django应用程序部署到Azure-服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆