gpt4 book ai didi

django - 尝试使用 Foreman 在 Gunicorn 上本地运行 Django 应用程序

转载 作者:行者123 更新时间:2023-12-02 03:12:45 24 4
gpt4 key购买 nike

我正在关注Getting Started with Django on Heroku tutorial
当我尝试使用 Foreman 在 Gunicorn 上运行 Django 应用程序时,我收到下一个错误回溯:

09:23:33 web.1  | started with pid 7012  
09:23:34 web.1 | 2013-05-06 09:23:34 [7012] [INFO] Starting gunicorn 0.17.2
09:23:34 web.1 | 2013-05-06 09:23:34 [7012] [INFO] Listening at: `http://0.0.0.0:5000` (7012)
09:23:34 web.1 | 2013-05-06 09:23:34 [7012] [INFO] Using worker: sync
09:23:34 web.1 | 2013-05-06 09:23:34 [7015] [INFO] Booting worker with pid: 7015
09:23:34 web.1 | 2013-05-06 09:23:34 [7015] [ERROR] Exception in worker process:
09:23:34 web.1 | Traceback (most recent call last):
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
09:23:34 web.1 | worker.init_process()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
09:23:34 web.1 | self.wsgi = self.app.wsgi()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 103, in wsgi
09:23:34 web.1 | self.callable = self.load()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 25, in load
09:23:34 web.1 | return util.import_app(self.app_uri)
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/util.py", line 372, in import_app
09:23:34 web.1 | __import__(module)
09:23:34 web.1 | File "/Users/cosmicMan66/DjangoDev/hepcat_server/hepcat_server/wsgi.py", line 27, in <module>
09:23:34 web.1 | from django.core.wsgi import get_wsgi_application
09:23:34 web.1 | ImportError: No module named django.core.wsgi
09:23:34 web.1 | Traceback (most recent call last):
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
09:23:34 web.1 | worker.init_process()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
09:23:34 web.1 | self.wsgi = self.app.wsgi()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 103, in wsgi
09:23:34 web.1 | self.callable = self.load()
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 25, in load
09:23:34 web.1 | return util.import_app(self.app_uri)
09:23:34 web.1 | File "/usr/local/lib/python2.7/site-packages/gunicorn/util.py", line 372, in import_app
09:23:34 web.1 | __import__(module)
09:23:34 web.1 | File "/Users/cosmicMan66/DjangoDev/hepcat_server/hepcat_server/wsgi.py", line 27, in <module>
09:23:34 web.1 | from django.core.wsgi import get_wsgi_application
09:23:34 web.1 | ImportError: No module named django.core.wsgi
09:23:34 web.1 | 2013-05-06 09:23:34 [7015] [INFO] Worker exiting (pid: 7015)
09:23:35 web.1 | 2013-05-06 09:23:35 [7012] [INFO] Shutting down: Master
09:23:35 web.1 | 2013-05-06 09:23:35 [7012] [INFO] Reason: Worker failed to boot.
09:23:35 web.1 | exited with code 3
09:23:35 system | sending SIGTERM to all processes
SIGTERM received

Procfile位于项目的根目录中,包含:

web: gunicorn hepcat_server.wsgi

settings.py位于hepcat_server目录

当我使用$ python manage.py run_gunicorn
Gunicorn 启动成功,我看到默认的 Django 页面

最佳答案

我在遵循您使用的 Heroku 设置页面时遇到了同样的问题。我在this page上找到了解决方案。我已将其复制在这里供后代使用:

In the root directory of your django project, create the Procfile file. then write this on it web: sh -c "cd djangoproject && gunicorn djangoproject.wsgi". then create another file called .env in the same location, write DJANGO_SETTINGS_MODULE=djangoproject.settings into it, this will help you setting the required env variable that cannot be set in djangoproject.wsgi module. run foreman start in order to test. What this does should be self explanatory giving the issue below.

When you deploy, after creating your application in heroku, set the env variable with this command heroku config:set DJANGO_SETTINGS_MODULE=djangoproject.settings, this is because the deployment fails before the file djangoproject/djangoproject/wsgi.py is run.

记住将“djangoproject”替换为您的 django 项目的名称。

关于django - 尝试使用 Foreman 在 Gunicorn 上本地运行 Django 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16394197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com