【问题标题】:Failed to find attribute 'application' in 'django'无法在“django”中找到属性“应用程序”
【发布时间】:2020-11-23 07:32:07
【问题描述】:

在运行时heroku logs --tail 我明白了

在“django”中找不到属性“application”

为什么会出现这个错误?

当我将代码推送到 heroku master 并部署时,我的部署成功,但出现此错误。我正确添加了requirements.txtProcFile。它在本地主机中完美运行。

【问题讨论】:

  • Please don't post screenshots of text。它们无法被搜索或复制,并且可用性差。相反,将代码作为文本直接粘贴到您的问题中。如果选择它并单击{} 按钮或Ctrl+K,则代码块将缩进四个空格,这将导致其呈现为代码。

标签: 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: 对不起我的英语不好

    【讨论】:

      猜你喜欢
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 2016-03-26
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      相关资源
      最近更新 更多