Django: Module not Found on Azure App Service - Azure DevOps CD

谁都会走 提交于 2021-02-11 12:51:53

问题


I am looking to set up a simple Django application on Azure App Service (Linux OS) by running an Azure Devops Build and Release pipeline. The application builds and creates a release without a problem.

However when the application has been released it runs into runtime errors.

2019-10-15T09:48:16.161816610Z ModuleNotFoundError: No module named 'django'

I run pip3 install -r requirements.txt as part of the bash post deployment script, and requirements.txt contains Django but it claims the requirement is already satisfied. Or if I bash into the App Service and run the same command it get the same message with the requirements already being satisfied.

Therefore my question is, why am I receiving a ModuleNotFoundError?


回答1:


This is a very normal issue we would meet during the application runtime. About the issue you are facing, there has different situations need to be considered.

1. If you has virtualenv, ensure the state of virtualenv is activated.

With the follow command to activate the virtualenv:

$ source ./{env-name}/bin/activate

For details info, you can check this doc.

2. Ensure the path of module is correct in Wsgi file:

For python runtime, it has Python module search path. If you did not specified the module path in Wsgi file, it will not get and read the Django module.

In your Wsgi file, it should has these script:

 sys.path.append(<module-path})

If you has specified the path, but still has the issue, please check this blog which described the sibling package.

Here has one detailed blog which about the virtualenv and package path.



来源:https://stackoverflow.com/questions/58392489/django-module-not-found-on-azure-app-service-azure-devops-cd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!