【问题标题】:Failed to find attribute 'application' in 'django'无法在“django”中找到属性“应用程序”
【发布时间】:2020-11-23 07:32:07
【问题描述】:
在运行时heroku logs --tail 我明白了
在“django”中找不到属性“application”
为什么会出现这个错误?
当我将代码推送到 heroku master 并部署时,我的部署成功,但出现此错误。我正确添加了requirements.txt 和ProcFile。它在本地主机中完美运行。
【问题讨论】:
标签:
django
heroku
hosting
web-hosting
heroku-api
【解决方案1】:
您似乎正在尝试运行在 Windows 中复制且名称中有空格的文件。引用或转义 Procfile 中的空格:
gunicorn "django - Copy.wsgi"
或者,更好的是,修复该文件的名称,相应地更改您的Procfile,提交并重新部署。
【解决方案2】:
我的设置也有同样的问题 gunicorn config is wrong config for django,来自:
web: gunicorn inventory:wsgi
解决这个问题:
web: gunicorn inventory.wsgi:application
inventory 是文件夹中名为 wsgi.py 的文件夹中名为 wsgi.py 的文件夹的示例名称,startproject django-admin 上的示例结构文件夹:
[projectname]/
├── [projectname]/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py -> here
└── manage.py
而应用是wsgi.py文件中的对象,例如:
"""
WSGI config for inventory project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'inventory.settings')
application = get_wsgi_application() #--> this object
p.s: 对不起我的英语不好