使用 Devops CI/CD 将 Django Web App 部署到 Azure 应用服务

2023-12-23

我正在尝试使用 CI/CD 管道(Microsoft 为应用程序部署提供的最基本的管道 - 我没有进行任何更改)将简单的 django web ap 部署到 Azure 应用程序服务。但是我收到以下错误:

2021-03-08T16:55:51.172914117Z   File "", line 219, in _call_with_frames_removed
2021-03-08T16:55:51.172918317Z   File "/home/site/wwwroot/deytabank_auth/wsgi.py", line 13, in 
2021-03-08T16:55:51.172923117Z     from django.core.wsgi import get_wsgi_application
2021-03-08T16:55:51.172927017Z ModuleNotFoundError: No module named 'django'

我检查了其他线程并尝试执行提到的所有操作,但它没有帮助,或者我遗漏了一些东西:

In wsgi.py我补充道:

import os
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..' )
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../licenses_api')
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../deytabank_auth')

from django.core.wsgi import get_wsgi_application


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'deytabank_auth.settings')

application = get_wsgi_application()

但仍然遇到同样的错误,django 无法识别。我可以看到 reuqirements.txt 已成功安装,并且其中包含所有必需的库(包括 Django)

我的 CI/CD yaml 文件如下所示:

# Python to Linux Web App on Azure
# Build your Python project and deploy it to Azure as a Linux Web App.
# Change python version to one thats appropriate for your application.
# https://learn.microsoft.com/azure/devops/pipelines/languages/python

trigger:
- develop

variables:
  # Azure Resource Manager connection created during pipeline creation
  azureServiceConnectionId: '***'

  # Web app name
  webAppName: 'DeytabankAuth'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

  # Environment name
  environmentName: 'DeytabankAuth'

  # Project root folder. Point to the folder containing manage.py file.
  projectRoot: $(System.DefaultWorkingDirectory)

  # Python version: 3.7
  pythonVersion: '3.7'

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: BuildJob
    pool:
      vmImage: $(vmImageName)
    steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '$(pythonVersion)'
      displayName: 'Use Python $(pythonVersion)'

    - script: |
        python -m venv antenv
        source antenv/bin/activate
        python -m pip install --upgrade pip
        pip install setup
        pip install -r requirements.txt
      workingDirectory: $(projectRoot)
      displayName: "Install requirements"

    - task: ArchiveFiles@2
      displayName: 'Archive files'
      inputs:
        rootFolderOrFile: '$(projectRoot)'
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true

    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      displayName: 'Upload package'
      artifact: drop

- stage: Deploy
  displayName: 'Deploy Web App'
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: DeploymentJob
    pool:
      vmImage: $(vmImageName)
    environment: $(environmentName)
    strategy:
      runOnce:
        deploy:
          steps:

          - task: UsePythonVersion@0
            inputs:
              versionSpec: '$(pythonVersion)'
            displayName: 'Use Python version'

          - task: AzureWebApp@1
            displayName: 'Deploy Azure Web App : DeytabankAuth'
            inputs:
              azureSubscription: $(azureServiceConnectionId)
              appName: $(webAppName)
              package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip

也许我需要在 Azure 应用服务中配置一些东西?但我不确定到底是什么。


I have met this issue before, and the problem might be your deployment method. Not sure which one you use, but the classic deployment center below is being deprecated, try use the new deployment center. enter image description here Checked your workflow with the one worked on my side, there is nothing different. So I will post the correct step worked on my side for you to refer.

  1. 检查你的项目locally以确保它能够成功运行。

  2. Create a new web app (this is to make sure no damage on your web app) and navigate to the Deployment center page. enter image description here

  3. Go to your GitHub and navigate to GitHub Action page to see the log. enter image description here

  4. Test your web app and check the file structure on KuDu site: https://{yourappname}.scm.azurewebsites.net/wwwroot/ enter image description here

You could test by click the browse button like what I did. enter image description here If you want to run command, go to this site: https://{yourappname}.scm.azurewebsites.net/DebugConsole enter image description here


顺便说一句,我发布了这个link https://stackoverflow.com/questions/66428914/azure-devops-for-python/66434028#66434028如果你需要使用 DevOps 进行部署.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Devops CI/CD 将 Django Web App 部署到 Azure 应用服务 的相关文章

随机推荐

  • Luhn算法逻辑

    我目前正在学习 Codecademy 的全栈工程师课程 到目前为止 我一直非常适应它 发现新事物 自己解决问题 但这对我的进步来说是一个严重的障碍 因为我似乎无法找出这个逻辑的问题 我并不是想质疑卢恩的算法 但说真的 我需要对此进行一些澄清
  • 如何在 TwiML 中生成半秒暂停?

    我正在尝试使用 Twilio 的 docs api twiml say动词 用于清楚地发音数字序列 我发现很难在每个数字之间产生自然的 半秒 停顿 我该如何正确地做到这一点 xml 命令仅采用以秒为单位的整数值 因此它太长而无法使用 从这里
  • 排序数组的紧凑数据结构

    我有一个表格 其中包含排序后的数字 例如 1 320102 2 5200100 3 92010023 4 112010202 5 332020201 6 332020411 5000000000 3833240522044511 50000
  • 如何清除 Silverlight/Windows Phone 7 中的导航历史记录?

    我正在制作一个具有登录 注销语义 对 Web 应用程序进行身份验证 的 Windows Phone 7 应用程序 当用户注销时 我导航回登录屏幕并忘记会话身份验证 这样做时 我还想清除导航历史记录 以便无法返回到期望它们已经经过身份验证的页
  • 安装 gdata 失败(在 64 位 Linux 上)

    我正在开发一个 R 脚本 它使用 gplots 库 因此在脚本的某个时刻 library gplots 叫做 使用 32 位 Linux 系统 Linux 3 2 0 33 generic pae 52 Ubuntu SMP i686 GN
  • 如何使用 Python 只保留 Pandas 数据框中的连续值

    我有一个看起来像这样的数据框 我想只保留每组中的连续年份 如下图 A组中的2005年和B组中的2009年和2011年被删除 我使用以下方法创建了年份差异列df year diff df groupby group Year diff 然后只
  • 无法打开 mysql 数据库中的文件

    我从github下载了员工数据库 在其网站上推荐mysql 但导入时出现错误 我该如何修复它 我不认为它是损坏的数据库 错误是 ERROR Failed to open file load salaries1 dump error 2 ER
  • ApolloGraphql FileNotFoundException: source/apollo/ generatedIR/debug/src (是一个目录)

    我正在尝试将 ApolloGraphql 添加到我的 android 项目中 但是当我尝试重建项目时 我得到 org gradle api UncheckedIOException java io FileNotFoundException
  • IE 11 和 IE Edge 获取 file.type 失败

    change btn file file getfileinfo getfileinfo function e var fileInput document getElementById fileupload var file fileIn
  • 机器人不接收消息

    我试图让我的机器人回复消息 但它不起作用 有人知道如何解决这个问题吗 Code const Discord require discord js const client new Discord Client intents GuildMe
  • 在 Visual Studio 2010 中调整大小时出现不需要的窗口

    我一直在 Visual Studio 2010 中从事一个使用 C 创建大型 Windows 窗体的项目 令我困扰的是 每当我觉得需要更改表单的布局并在设计器视图中打开它时 它都会调整为稍小的尺寸集 每次这样做时 我都必须恢复尺寸并在某些面
  • 生成字符串的所有可能的连续单词组合

    我想生成特定字符串的所有可能的连续单词组合 给定最小长度作为参数 假设我有 hello 结果将是 最小长度为 3 hel ello ello hell ello hello 我实现这一目标的一种方法是通过 def get all word
  • 使用 cURL 请求 instagram api 访问令牌

    我正在尝试从 instagram api 获取访问令牌 这是文档的示例请求 curl F client id CLIENT ID F client secret CLIENT SECRET F grant type authorizatio
  • 在 C# 中获取指向 KeyValuePair 数组的不安全指针

    我有很多KeyValuePair
  • 如何配置“全有或全无”的 Ansible 剧本?

    我有很多服务器需要经常修补 我计划使用 Ansible 来协调修补过程 这里要注意的是 它必须是 全有或全无 的修补程序 要么所有服务器都打补丁 要么没有 我正在考虑的剧本任务如下 1 转到所有服务器并拍摄 lvm 快照 2 IIF 任务
  • 如何在勾选或取消勾选部分项目时勾选和取消勾选所有项目

    JavaFX 检查组合框 如何在选中或取消选中某些项目时选中和取消选中所有项目 点击项目全部时勾选全部 https i stack imgur com Yk0D1 png 取消选中项目 All 时取消选中全部 https i stack i
  • Xamarin.ios 构建因 HEALTHKIT 参考而被拒绝

    由于引用 HEALTHKIT 框架 我的 xamarin ios 版本已被应用程序中心拒绝 仅因为某些第三方库 我无法将链接器设置为 SDK 框架 另外 我已经上传了一个带有 mtouch 参数 linkskip HealthKit 的ne
  • 一个appdomain可以限制在一个目录吗?

    我正在开发一个插件主机 插件应该具有尽可能少的信任 但是我希望插件能够读取和写入文件 是否可以将加载程序集的 AppDomain 限制为只能访问一个目录进行读写 其他选项和方法也值得赞赏 例如将文件数据从主机流式传输到插件 读取 以及从插件
  • 如何在Tomcat中部署AAR

    我有使用 Ant 生成的 AAR 格式的文件 但我想将其部署在 Tomcat 服务器中 Tomcat 仅支持 WAR 文件 我尝试使用命令生成war文件jar cvf smth war但如果没有清单 它就不起作用 有人知道如何将 AAR 转
  • 使用 Devops CI/CD 将 Django Web App 部署到 Azure 应用服务

    我正在尝试使用 CI CD 管道 Microsoft 为应用程序部署提供的最基本的管道 我没有进行任何更改 将简单的 django web ap 部署到 Azure 应用程序服务 但是我收到以下错误 2021 03 08T16 55 51