Python 如何在本地为Heroku运行Django项目

Python 如何在本地为Heroku运行Django项目,python,django,heroku,Python,Django,Heroku,我有一个Django项目,结构如下: """ WSGI config for users_groups 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/1.11/howto/deployment/wsgi/ """ im

我有一个Django项目,结构如下:

"""
WSGI config for users_groups 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/1.11/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "users_groups.settings")

application = get_wsgi_application()
在Procfile中,我有这个代码

web: gunicorn team-app.wsgi --log-file -
这是requirements.txt

env是本地安装的virtualenv。当我进入根文件夹team app并运行命令heroku local web时,我得到以下错误:

因此,问题很重要:没有名为team-app.wsgi的模块,我相信Procfile或其他东西的位置不正确。用户组中的wsgi.py文件如下所示:

"""
WSGI config for users_groups 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/1.11/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "users_groups.settings")

application = get_wsgi_application()

如果需要,我可以提供更多信息。如何解决这个问题?

这里有两个问题。第一个与Django有关:

ImportError:没有名为team-app.wsgi的模块

您的wsgi.py文件位于users\u groups/目录中,因此您的程序文件应该引用users\u groups.wsgi:

包含整个项目的顶级目录的名称是不相关的

第二个问题与Heroku有关。Heroku希望Django目录是存储库的根目录。将Procfile移动到src/,然后运行heroku本地web应该可以让您启动并在本地运行


部署到Heroku时,必须确保当前src/目录是根目录。这可能意味着将一些文件移动到src/中,并在那里重新创建/重构您的Git存储库,也可能意味着将当前src/中的所有内容都移动到一个级别。

这不起作用,我收到错误ImportError:没有名为users\u groups.wsgi的模块。我认为应该是project_name.wsgi。我还尝试了src.users\u groups.wsgi和src.main.users\u groups.wsgi这样的版本。我想问题已经解决了,但到目前为止还没有解决。很难从你的截图中分辨出来,但是看起来你的requirements.txt和Procfile在一个子目录中?他们在那里。看起来整个Django应用程序都在一个名为src/的子目录中;它可能还必须向上移动一个级别。通常我会使用它作为我的项目根。您的Git存储库位于src/级别还是团队应用程序/级别?1。requirements.txt和Procfile都位于团队应用程序的顶层。2.这是正确的,整个Django应用程序都在src文件夹中。我不相信这是一个问题,还是真的?3.Git生活在团队应用程序/级别中。为了便于理解,我为项目结构添加了一个新的图片。当我第一次在Heroku上使用Django时,我记得必须使用我的主Django目录作为我的项目根目录。那是几年前的事了,所以也许它不再适用了,但值得一试。尝试将Procfile移到src/,然后将cd移到src/,并尝试从那里运行heroku local web,Procfile引用users_groups.wsgi。这实际上是可行的。你想把它写下来作为答案吗?我相信这会有帮助的。太好了!我刚刚更新了我的答案。
web: gunicorn users_groups.wsgi --log-file -