在 DjangoGirls 教程中无法部署到 Heroku

Posted

技术标签:

【中文标题】在 DjangoGirls 教程中无法部署到 Heroku【英文标题】:Can't deploy to Heroku in DjangoGirls tutorial 【发布时间】:2015-06-11 12:57:02 【问题描述】:

我正在关注这个 DjangoGirls 教程:http://tutorial.djangogirls.org/en/deploy/README.html

当我尝试打开我的应用程序的 /admin 页面时,因为教程指出:

"由于到目前为止我们只为应用创建了管理视图,因此添加 admin/ 到网址(例如https://djangogirlsblog.herokuapp.com/admin/)查看 我们网络应用的工作页面。”

我仍然收到以下浏览器消息:

应用程序错误应用程序和您的页面发生错误 无法送达。请稍后再试。

如果您是应用程序所有者,请查看您的日志以了解详细信息。

这是我的项目布局:

djangogirls
|--mysite/
  |--blog/
  |--db.sqlite3
  |----manage.py
  |----mysite/
|--myvenv/
|--Procfile
|--requirements.txt
|--runtime.txt
|--.gitignore

这些是.gitignore的内容:

myvenv
__pycache__
staticfiles
local_settings.py
db.sqlite3
*.py[co]
*.pyc

这些是我的 mysite/wsgi.py 的内容

import os

from django.core.wsgi import get_wsgi_application

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

application = get_wsgi_application()

from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(application)

这些是Procfile的内容

web: gunicorn djangogirls.wsgi

教程告诉我们把mysite.wsgi复制出来,但是我在另一篇帖子里看到应该是project_name.wsgi,所以我改了这个。

runtime.txt:python-2.7.6

requirements.txt:

dj-database-url==0.3.0
Django==1.8
gunicorn==19.3.0
whitenoise==1.0.6
psycopg2==2.5.4

我知道这是一个很长的帖子,我提前为此道歉,我想提供更多信息而不是不够,我不完全明白在这种情况下我应该看什么重要的事情!

这是我的heroku日志:

2015-04-07T02:30:18.990628+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 189, in run
2015-04-07T02:30:18.990685+00:00 app[web.1]:     super(Application, self).run()
2015-04-07T02:30:18.990710+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
2015-04-07T02:30:18.990746+00:00 app[web.1]:     Arbiter(self).run()
2015-04-07T02:30:18.990823+00:00 app[web.1]:     self.manage_workers()
2015-04-07T02:30:19.728739+00:00 heroku[web.1]: Process exited with status 1
2015-04-07T02:30:19.750144+00:00 heroku[web.1]: State changed from starting to crashed
2015-04-07T02:30:19.750381+00:00 heroku[web.1]: State changed from crashed to starting
2015-04-07T02:30:22.860260+00:00 heroku[web.1]: Starting process with command `gunicorn djangogirls.wsgi`
2015-04-07T02:30:24.130180+00:00 app[web.1]: [2015-04-07 02:30:24 +0000] [3] [INFO] Listening at: http://0.0.0.0:24389 (3)
2015-04-07T02:30:24.137056+00:00 app[web.1]: [2015-04-07 02:30:24 +0000] [9] [INFO] Booting worker with pid: 9
2015-04-07T02:30:24.170773+00:00 app[web.1]: Traceback (most recent call last):
2015-04-07T02:30:24.170770+00:00 app[web.1]: [2015-04-07 02:30:24 +0000] [10] [ERROR] Exception in worker process:
2015-04-07T02:30:24.170775+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
2015-04-07T02:30:24.170777+00:00 app[web.1]:     worker.init_process()
2015-04-07T02:30:24.130312+00:00 app[web.1]: [2015-04-07 02:30:24 +0000] [3] [INFO] Using worker: sync
2015-04-07T02:30:24.170780+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-04-07T02:30:24.170778+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
2015-04-07T02:30:24.170791+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-04-07T02:30:24.170792+00:00 app[web.1]:     __import__(module)
2015-04-07T02:30:24.170783+00:00 app[web.1]:     self.callable = self.load()
2015-04-07T02:30:24.170784+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-04-07T02:30:24.170786+00:00 app[web.1]:     return self.load_wsgiapp()
2015-04-07T02:30:24.170798+00:00 app[web.1]:     worker.init_process()
2015-04-07T02:30:24.170793+00:00 app[web.1]: ImportError: No module named djangogirls.wsgi
2015-04-07T02:30:24.170795+00:00 app[web.1]: Traceback (most recent call last):
2015-04-07T02:30:24.170796+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
2015-04-07T02:30:24.170788+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-04-07T02:30:24.170789+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-04-07T02:30:24.170806+00:00 app[web.1]:     return self.load_wsgiapp()
2015-04-07T02:30:24.170807+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-04-07T02:30:24.170808+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-04-07T02:30:24.170799+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
2015-04-07T02:30:24.170811+00:00 app[web.1]:     __import__(module)
2015-04-07T02:30:24.170802+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-04-07T02:30:24.170803+00:00 app[web.1]:     self.callable = self.load()
2015-04-07T02:30:24.170804+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-04-07T02:30:24.170800+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-04-07T02:30:24.170781+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-04-07T02:30:24.176154+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 189, in run
2015-04-07T02:30:24.176159+00:00 app[web.1]:     Arbiter(self).run()
2015-04-07T02:30:24.176144+00:00 app[web.1]: Traceback (most recent call last):
2015-04-07T02:30:24.176162+00:00 app[web.1]:     self.manage_workers()
2015-04-07T02:30:24.176151+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
2015-04-07T02:30:24.176168+00:00 app[web.1]:     time.sleep(0.1 * random.random())
2015-04-07T02:30:24.176153+00:00 app[web.1]:     WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2015-04-07T02:30:24.176156+00:00 app[web.1]:     super(Application, self).run()
2015-04-07T02:30:24.170877+00:00 app[web.1]: [2015-04-07 02:30:24 +0000] [10] [INFO] Worker exiting (pid: 10)
2015-04-07T02:30:24.176163+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
2015-04-07T02:30:24.176148+00:00 app[web.1]:   File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2015-04-07T02:30:24.176165+00:00 app[web.1]:     self.spawn_workers()
2015-04-07T02:30:24.176149+00:00 app[web.1]:     sys.exit(run())
2015-04-07T02:30:24.176166+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 541, in spawn_workers
2015-04-07T02:30:24.170813+00:00 app[web.1]: ImportError: No module named djangogirls.wsgi
2015-04-07T02:30:24.176161+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 174, in run
2015-04-07T02:30:24.178515+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2015-04-07T02:30:24.170810+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-04-07T02:30:24.176158+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
2015-04-07T02:30:24.178505+00:00 app[web.1]:     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2015-04-07T02:30:24.141236+00:00 app[web.1]:     self.callable = self.load()
2015-04-07T02:30:24.176170+00:00 app[web.1]:     self.reap_workers()
2015-04-07T02:30:24.176169+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 214, in handle_chld
2015-04-07T02:30:24.176172+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
2015-04-07T02:30:24.141232+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-04-07T02:30:24.141237+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-04-07T02:30:24.141239+00:00 app[web.1]:     return self.load_wsgiapp()
2015-04-07T02:30:24.141254+00:00 app[web.1]:     self.wsgi = self.app.wsgi()
2015-04-07T02:30:24.141229+00:00 app[web.1]:     worker.init_process()
2015-04-07T02:30:24.129374+00:00 app[web.1]: [2015-04-07 02:30:24 +0000] [3] [INFO] Starting gunicorn 19.3.0
2015-04-07T02:30:24.141223+00:00 app[web.1]: [2015-04-07 02:30:24 +0000] [9] [ERROR] Exception in worker process:
2015-04-07T02:30:24.141231+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
2015-04-07T02:30:24.141246+00:00 app[web.1]: ImportError: No module named djangogirls.wsgi
2015-04-07T02:30:24.141228+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
2015-04-07T02:30:24.141248+00:00 app[web.1]: Traceback (most recent call last):
2015-04-07T02:30:24.141226+00:00 app[web.1]: Traceback (most recent call last):
2015-04-07T02:30:24.141251+00:00 app[web.1]:     worker.init_process()
2015-04-07T02:30:24.141234+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-04-07T02:30:24.141252+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
2015-04-07T02:30:24.141240+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-04-07T02:30:24.141249+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
2015-04-07T02:30:24.141242+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-04-07T02:30:24.141243+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-04-07T02:30:24.141244+00:00 app[web.1]:     __import__(module)
2015-04-07T02:30:24.141262+00:00 app[web.1]:     return util.import_app(self.app_uri)
2015-04-07T02:30:24.141256+00:00 app[web.1]:     self.callable = self.load()
2015-04-07T02:30:24.141259+00:00 app[web.1]:     return self.load_wsgiapp()
2015-04-07T02:30:24.141263+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
2015-04-07T02:30:24.141255+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2015-04-07T02:30:24.141258+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
2015-04-07T02:30:24.141260+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
2015-04-07T02:30:24.166744+00:00 app[web.1]: [2015-04-07 02:30:24 +0000] [10] [INFO] Booting worker with pid: 10
2015-04-07T02:30:24.141264+00:00 app[web.1]:     __import__(module)
2015-04-07T02:30:24.141266+00:00 app[web.1]: ImportError: No module named djangogirls.wsgi
2015-04-07T02:30:24.141324+00:00 app[web.1]: [2015-04-07 02:30:24 +0000] [9] [INFO] Worker exiting (pid: 9)
2015-04-07T02:30:24.956327+00:00 heroku[web.1]: State changed from starting to crashed
2015-04-07T02:30:24.942505+00:00 heroku[web.1]: Process exited with status 1
2015-04-07T02:30:39.168025+00:00 heroku[api]: Scale to web=1 by paulzovighian@gmail.com
2015-04-07T02:30:45.176867+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=jtestblog.herokuapp.com request_id=457b2a51-1fc2-4f83-8316-c8fb0635c97b fwd="67.70.37.25" dyno= connect= service= status=503 bytes=
2015-04-07T02:30:48.582173+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=jtestblog.herokuapp.com request_id=137c668e-8d93-4c14-b98d-d1737adabf97 fwd="67.70.37.25" dyno= connect= service= status=503 bytes=
2015-04-07T02:30:48.976617+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/admin/" host=jtestblog.herokuapp.com request_id=8ad477b3-4348-4a90-b7bf-53791d7c5e02 fwd="67.70.37.25" dyno= connect= service= status=503 bytes=
2015-04-07T02:30:54.502759+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/admin/" host=jtestblog.herokuapp.com request_id=c074764e-4ac9-4205-8762-8073bf3cd7d6 fwd="67.70.37.25" dyno= connect= service= status=503 bytes=

这似乎是本教程中较难的阶段之一,我似乎无法弄清楚这个错误究竟意味着什么......提前感谢任何可以提供帮助的人,我真的很感激!

【问题讨论】:

从您的项目布局中,我假设 wsgi 文件在项目文件夹内的一级.. 在这种情况下,您可以使用 --pythonpath 给出确切的路径,如web: gunicorn --pythonpath app app.wsgi ?? 你的项目是叫“mysite”还是“djangogirls”? @RajaSimon 如果我进行更改,Heroku 会给我一条新消息“在服务器上找不到请求的 URL/。 @DanielRoseman 项目名称是 djangogirls,mysite 文件夹只是 django 使用的标准项目文件夹模板。抱歉,如果不清楚。 但这不是它的工作原理。当您执行django-admin.py createproject &lt;project_name&gt; 时,Django 会创建一个名为“project_name”的外部文件夹和一个名为“project-name”的内部文件夹。他们应该是一样的,我不明白你是怎么得到一个叫“djangogirls”和一个叫“mysite”的。 【参考方案1】:

问题出在您的 Procfile 中。说明说要做:

web: gunicorn mysite.wsgi

但你已经把“djangogirls”而不是“mysite”。正如您在 cmets 中解释的那样,您的项目实际上称为“mysite”,而“djangogirls”只是包含文件夹的名称。

【讨论】:

您好 Daniel,感谢您的回复 - 这是我最初的设置,我不断收到相同的应用程序错误。我最终做出了这个改变web: gunicorn --pythonpath app app.wsgi,它奏效了。除此之外,每当我运行初始的django-admin startproject projectname 命令时,我不应该假设这是此类教程中提到的项目名称吗?因为我还没有接触到我的项目的布局,而且放 mysite.wsgi 肯定比 djangogirls.wsgi 更直观(我猜它只是需要完整路径才能知道它在哪里)【参考方案2】:

如果你在根目录下项目文件夹,那么你必须给出确切的路径,这样 gunicorn 才能更好地服务..:)

点赞web: gunicorn --pythonpath app app.wsgi

更多信息pythonpath

【讨论】:

以上是关于在 DjangoGirls 教程中无法部署到 Heroku的主要内容,如果未能解决你的问题,请参考以下文章

SyntaxError:Generator表达式必须是parenthezised / python manage.py migrate

已部署到Heroku的Rails应用程序无法更新

提交表单html django

无法将python代码部署到heroku

迁移时django sqlite到postgresql ProgrammingError

部署到 Google Cloud Run 时 Docker 容器无法启动