"ModuleNotFoundError:没有名为'django'的模块"尝试在Azure上部署Django服务器时 [英] "ModuleNotFoundError: No module named 'django'" when trying to deploy Django server on Azure

查看:144
本文介绍了"ModuleNotFoundError:没有名为'django'的模块"尝试在Azure上部署Django服务器时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Azure上部署Django网站后,出现错误消息:

After I tried to deploy my Django website on Azure, I got an error saying:

ModuleNotFoundError: No module named 'django'

我在Django项目的根目录中添加了requirements.txt,是否还有其他内容?我曾尝试从Kudu BASH安装Django,但它卡在清理"上.

I added a requirements.txt in the root directory of my Django project, am I missing anything else? I've tried to install Django from Kudu BASH but it gets stuck on "Cleaning Up".

这是完整的错误: https://pastebin.com/z5xxqM08

我使用Django-2.2和Python 3.6.8构建了网站.

I built the site using Django-2.2 and Python 3.6.8.

推荐答案

仅归纳为其他人的答案.根据您的错误信息,我可以看到您尝试将Django应用程序部署到基于Docker的Linux上的Azure WebApp.因此,有两个官方文档将对您有所帮助.

Just summarized as an answer for other people. According to your error information, I can see that you tried to deploy your Django app to Azure WebApp on Linux based on Docker. So there are two offical documents will help as below.

  1. 快速入门:在Azure应用中创建Python应用Linux上的服务
  2. 配置Linux Python应用用于Azure应用服务
  1. Quickstart: Create a Python app in Azure App Service on Linux
  2. Configure a Linux Python app for Azure App Service

错误ModuleNotFoundError: No module named 'django'表示Azure Linux WebApp的容器上未安装django程序包.

The error ModuleNotFoundError: No module named 'django' indicated that there is not django package installed on the container of Azure Linux WebApp.

由于上述#2文档的Container characteristics的内容如下,

Due to the content of Container characteristics of #2 document above as below,

要安装其他软件包,例如Django,请使用pip freeze > requirements.txt在项目的根目录中创建一个requirements.txt文件.然后,使用Git部署将项目发布到App Service,该部署会在容器中自动运行pip install -r requirements.txt来安装应用程序的依赖项.

To install additional packages, such as Django, create a requirements.txt file in the root of your project using pip freeze > requirements.txt. Then, publish your project to App Service using Git deployment, which automatically runs pip install -r requirements.txt in the container to install your app's dependencies.

因此,可能的原因是requirements.txt文件不在部署后的项目或容器的当前路径中,该路径应为容器或项目根目录上的/home/site/wwwroot/requirements.txt,例如官方示例

So the possible reason is the requirements.txt file not in the corrent path of your project or container after deployed, which path should be /home/site/wwwroot/requirements.txt on the container or the root of your project like the offical sample Azure-Samples/djangoapp on GitHub.

这篇关于"ModuleNotFoundError:没有名为'django'的模块"尝试在Azure上部署Django服务器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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