git 如何在 Microsoft Azure 云服务上部署 django web 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41361449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:31:11  来源:igfitidea点击:

How to deploy django web application on Microsoft Azure cloud services

pythondjangogitazuredeployment

提问by Maninder Singh

I have a existing django web application currently deployed on aws. I want to deploy it on Microsoft Azure by using cloud services. How to create config files for deploying web app on Azure? How to access environment variables on Azure? I am not using Visual Studio. I am developing web app in linux env and using git for code management. Please help

我有一个现有的 django Web 应用程序,目前部署在 aws 上。我想使用云服务将其部署在 Microsoft Azure 上。如何创建配置文件以在 Azure 上部署 Web 应用程序?如何访问 Azure 上的环境变量?我没有使用 Visual Studio。我正在 linux env 中开发 Web 应用程序并使用 git 进行代码管理。请帮忙

回答by Peter Pan

It sounds like you want to know which way is the best choice for deploying a django app via Git for code management on Linux, using Cloud Services or App Services on Azure.

听起来您想知道哪种方式是通过 Git 部署 django 应用程序以在 Linux 上进行代码管理、使用云服务或 Azure 上的应用程序服务的最佳选择。

Per my experience, I think deploying a pure web app into App Service on Azure via Git on Linux is the simplest way for you. You can refer to the offical docuemnts below to know how to do it via Azure CLI or only Git.

根据我的经验,我认为通过 Linux 上的 Git 将纯 Web 应用程序部署到 Azure 上的应用服务中是最简单的方法。您可以参考下面的官方文档,了解如何通过 Azure CLI 或仅通过 Git 执行此操作。

  1. Deploy your first Python web app to Azure in five minutes
  2. Local Git Deployment to Azure App Service
  1. 在五分钟内将您的第一个 Python Web 应用程序部署到 Azure
  2. 本地 Git 部署到 Azure 应用服务

And there is a code sampleof Django on App Service as reference that you can know how to configure it for running on Azure.

并且有一个Django on App Service的代码示例作为参考,您可以了解如何配置它以在 Azure 上运行。

However, if your app need more powerful features & performance, using Cloud Services for your django app is also a better way than using VM directly. Also as references, please view the document Python web and worker roles with Python Tools for Visual Studioto know how to let Azure support Python & Django on Cloud Services, and you can create & deploy it via Azure portalin the browser on Linux. Meanwhile, thanks for the third party GitHub sampleof Django WebRole for Cloud Service which you can refer to know how to create a cloud service project structure without PTVS for VS on Linux.

但是,如果您的应用程序需要更强大的功能和性能,那么为您的 django 应用程序使用云服务也是比直接使用 VM 更好的方法。同样作为参考,请查看文档Python Web 和使用 Visual Studio 的 Python 工具的辅助角色,了解如何让 Azure 支持云服务上的 Python 和 Django,并且您可以在 Linux 上的浏览​​器中通过 Azure 门户创建和部署它。同时,感谢第三方 GitHub 示例Django WebRole for Cloud Service,您可以参考了解如何在 Linux 上为 VS 创建没有 PTVS 的云服务项目结构。

Hope it helps.

希望能帮助到你。

回答by Mitch Stewart

I read this post, decided the how-to guides Peter Pan posted looked good, and set off on my own. With my one business day's worth of experience if you are looking to deploy your app to Azure, start with the Marketplace Django appand go from there. Reason being the virtual environment comes with it along with the activate script needed to run the virtual environment and the web.config is setup for you. If you follow the start from scratch how-to guides, these are the hardest parts to setup correctly. Once you create the app service from the template, do a git clone of the repo to your local machine. Make a small change and push it back up by running the command below in bash.

我读了这篇文章,认为彼得潘发布的操作指南看起来不错,于是我自己出发了。如果您希望将应用程序部署到 Azure,请从Marketplace Django 应用程序开始,然后从那里开始。原因是虚拟环境与运行虚拟环境所需的激活脚本一起提供,并且 web.config 已为您设置。如果您按照从头开始的操作指南,这些是最难正确设置的部分。从模板创建应用服务后,将 repo 的 git clone 复制到本地计算机。通过在 bash 中运行下面的命令,做一个小的改变并把它推回去。

az webapp deployment source config-local-git --name <app name> --resource-group <group name> --query url --output tsv

Use the result of the command to add the git repo as a remote source.

使用命令的结果将 git repo 添加为远程源。

git remote add azure https://<ftp_credential>@<app_name>.scm.azurewebsites.net/<app_name>.git

Finally, commit your changes and deploy

最后,提交您的更改并部署

git add -A
git commit -m "Test change"
git push azure remote

A couple of side notes

几个边注

If you do not have your bash environment setup, you'll need to do so to use the az commands. The marketplace app does run error-free locally. I have not dug into this yet.

如果您没有设置 bash 环境,则需要这样做才能使用 az 命令。市场应用程序在本地运行时没有错误。我还没有深入研究这个。

Good luck!

祝你好运!