Python django.core.exceptions.ImproperlyConfigured:无法加载 WSGI 应用程序“应用程序”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41441832/
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-08-20 00:58:15  来源:igfitidea点击:

django.core.exceptions.ImproperlyConfigured: WSGI application 'application' could not be loaded

pythondjangoopenshiftwsgiopenshift-nextgen

提问by

The scenario is,

场景是,

I cloned the Django code for OpenShift-V3 from here. When I run the code using python manage.py runservergetting an error as,

我从这里克隆了 OpenShift-V3 的 Django 代码。当我使用python manage.py runserver获取错误运行代码时,

django.core.exceptions.ImproperlyConfigured: WSGI application 'application' could not be loaded; Error importing module: 'application doesn't look like a module path

django.core.exceptions.ImproperlyConfigured:无法加载 WSGI 应用程序“应用程序”;导入模块时出错:“应用程序看起来不像模块路径

I didn't add anything to the code and the required packages are already satisfied.

我没有在代码中添加任何内容,所需的包已经满足。

采纳答案by

Go to django-ex/project/settings.py

转到 django-ex/project/settings.py

Change the line in settings.pyas below

更改settings.py 中的行,如下所示

WSGI_APPLICATION = 'application'toWSGI_APPLICATION = 'wsgi.application'

WSGI_APPLICATION = 'application'WSGI_APPLICATION = 'wsgi.application'

That's it :(

就是这样 :(

回答by Hasan

I used a middleware CorsMiddleware but forget to install it so after install, it works perfectly.

我使用了一个中间件 CorsMiddleware 但忘记安装它,所以安装后,它运行良好。

pip install django-cors-headers.

pip 安装 django-cors-headers。

So check something like it you may miss something like it.

所以检查类似的东西,你可能会错过类似的东西。

回答by Vladimir

If you run django project locally for development, just remove WSGI_APPLICATION variable from settings.py module. It needs in prod/stage settings, for example settings_prod.py

如果您在本地运行 django 项目进行开发,只需从 settings.py 模块中删除 WSGI_APPLICATION 变量。它需要在 prod/stage 设置中,例如 settings_prod.py

回答by Ngatia Frankline

Do you have Django Debug Toolbar

你有 Django 调试工具栏吗

Remove it and check if the problem goes away. Possible occurences:

删除它并检查问题是否消失。可能出现的情况:

pip uninstall django-debug-toolbar

INSTALLED_APPS = [
    ...
    'debug_toolbar',
    ...
]

MIDDLEWARE = [
    ...
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    ...
]

回答by uniqueomokenny

I was using django-cors-headers, then I thought I haven't implemented cors in my project, so went ahead to install django-cors-middleware, then it's started giving the wsgi exception, so i checked the stack trace and I found out that it's django-cors-headers and django-cors-middleware conflicting each other. I had to uninstall django-cors-middleware but it's still gives the same exception, so uninstall django-cors-headers too then reinstall and everything works fine....

我正在使用 django-cors-headers,然后我以为我还没有在我的项目中实现 cors,所以继续安装 django-cors-middleware,然后它开始给出 wsgi 异常,所以我检查了堆栈跟踪,我发现这是 django-cors-headers 和 django-cors-middleware 相互冲突。我不得不卸载 django-cors-middleware 但它仍然给出相同的例外,所以也卸载 django-cors-headers 然后重新安装,一切正常......

回答by daggett

Read carefully, it might say "The above exception was the direct cause of the following exception: ...". And the "above exception" being you forgot to install whitehoise. Run pip install whitenoise, it worked for me.

仔细阅读,它可能会说“上述异常是以下异常的直接原因:......”。而“上述例外”是你忘记安装白屋。运行pip install whitenoise,它对我有用。

回答by B.Hatuwal

in settings.py file change as follows:

在 settings.py 文件中更改如下:

WSGI_APPLICATION = 'your_project_name.wsgi.application'

WSGI_APPLICATION = 'your_project_name.wsgi.application'

回答by MrE

note that any error in importing modules anywhere prior to starting the wsgi application will also prompt this message, so first look at the trace and start from the top in fixing issues.

请注意,在启动 wsgi 应用程序之前在任何位置导入模块时发生的任何错误也会提示此消息,因此首先查看跟踪并从顶部开始修复问题。

I ported a Django app from python 2.7 to python3 and add all sorts of module import issues, not connected to this issue directly.

我将 Django 应用程序从 python 2.7 移植到 python3 并添加了各种模块导入问题,没有直接连接到这个问题。