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

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

问题描述

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

我做了以下事情:

  • 启动VS2017,用Django Web Project"模板新建一个项目.这将创建一个带有引导模板的 Django 网页 - 简单,并且一切都在本地运行良好.

  • 在 VS 中,转到 Connected Services => Publish,选择Microsft Azure App Service",创建一个新的 App Service 和一个 App Plan.实例创建成功.

  • 点击发布"通过 VS WebDeploy 发布.控制台中的一切看起来都不错,最后显示 Publish: 1 succeeded, 0 failed, 0 skipped.

这会导致标准 Azure Welcome-start-page hostingstart.html 显示,而不是 Django 页面.删除该 html 文件后,只有一个 无法显示页面,因为发生了内部服务器错误..我尝试了各种方法:转到portal.azure.com应用程序设置",将Python版本从关闭"设置为3.4"(实际上我想要3.5,MS的教程之一使用它 - 但任何都可以现在) - 然后只有一个 hostingstart-python.html 显示,仍然没有 Django.我尝试在 VS 中通过Add => New Item => Azure web.config (FastCGI)"添加默认 web.config.我尝试使用 WSGI_HANDLER 的各种值(例如 django.core.handlers.wsgi.WSGIHandler())和 DJANGO_SETTINGS_MODULE 编辑该 web.config>(例如mydjangopage.settings),我尝试将wfastcgi"添加到requirements.txt等.总是得到一个服务器错误.

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

解决方案

目前,VS 2017 中的发布支持处于过渡期.在接下来的几次更新中,我们希望将其恢复为一键式系统(在此过程中,可以从任何地方发布 Python 应用程序,而不仅仅是在 VS 中),但现在有几个手动步骤.

(我将总结以下步骤,但规范文档将在
(来源:windows.net)

  • 将您的 web.config 文件配置为您在 scriptProcessor 属性中安装的站点扩展的正确路径(类似于 D:homepython361x64python.exe - 查看每个扩展的描述以获取实际路径 - VS 2017 还包含项目模板来帮助设置这些,因此请查看 Add New Item 以获得想法)

  • 根据需要更新 WSGI_HANDLERDJANGO_SETTINGS_MODULE 变量(Django 应用程序的 WSGI_HANDLER 的典型值为 myapp.wsgi.application,假设你的项目中有一个 wsgi.py 文件)

  • 通过 VS 发布您的网站.

  • 使用 console 来安装你的包 - 例如D:homepython361x64python.exe -m pip install -r requirements.txt

  • 如果事情已经在运行,此时您可能需要重新启动您的站点,但通常您现在可以通过 VS 快速发布,而无需重新安装 Python 或任何包.

    如果您使用 JSON 模板通过 ARM 部署站点,您还可以在此处指定站点扩展:(来自 这里)

    资源":[{apiVersion":2015-08-01",名称":[参数('siteName')]",类型":Microsoft.Web/sites",...资源":[{apiVersion":2015-08-01",名称":python352x64",类型":站点扩展",属性":{ },取决于":[[resourceId('Microsoft.Web/sites', parameters('siteName'))]"]},...

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

    I've done the following:

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

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

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

    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.

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

    解决方案

    Right now, publishing support in VS 2017 is in a bit of a transition period. In the next couple of updates we want to get it back to a one-click system (and in the process, make it possible to publish Python apps from anywhere, not just within VS), but for now there are a couple of manual steps.

    (I'll summarize the steps below, but the canonical documentation will be at https://aka.ms/PythonOnAppService - right now it's a blog post with these steps and some of the backstory)

    1. After creating your new site (either through the portal or through VS - publishing content is okay too), install one of the Python site extensions
      (source: windows.net)

    2. Configure your web.config file to have the correct path to the site extension you installed in the scriptProcessor attribute (something like D:homepython361x64python.exe - see the description of each extension for the actual paths - VS 2017 also includes item templates to help set these up, so look through Add New Item for ideas)

    3. Update the WSGI_HANDLER and DJANGO_SETTINGS_MODULE variables as necessary (a typical value for WSGI_HANDLER for a Django app is myapp.wsgi.application, assuming you have a wsgi.py file in your project)

    4. Publish your site through VS.

    5. Use the console to install your packages - e.g. D:homepython361x64python.exe -m pip install -r requirements.txt

    You may need to restart your site at this point if things were already running, but in general you can now publish quickly through VS without having to reinstall Python or any packages.

    If you are deploying your site through ARM with a JSON template, you can also specify the site extension there: (from here)

    "resources": [
      {
        "apiVersion": "2015-08-01",
        "name": "[parameters('siteName')]",
        "type": "Microsoft.Web/sites",
        ...
        "resources": [
          {
            "apiVersion": "2015-08-01",
            "name": "python352x64",
            "type": "siteextensions",
            "properties": { },
            "dependsOn": [
              "[resourceId('Microsoft.Web/sites', parameters('siteName'))]"
            ]
          },
        ...
    

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

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