我试图在Heroku上部署我的django rest框架应用程序。我读过许多类似的问题,但我很困惑。我的应用程序结构不对,或者我遗漏了一些东西。
这是我在git上的结构:
.gitignore
requirements.txt
src
|
--authorization
--core
--static
--staticfiles
--Procfile
--manage.py
--suacm
|
---asgi.py
---settings.py
---urls.py
---wsgi.py授权和核心是我的django项目下的应用程序。在heroku部署之前,没有静态或静态文件。但它会自动创建静态文件。然后,我还创建了静态的,并遵循指示,使其通过改变settings.py。如果有人帮我解决我在heroku的问题,以及为什么它不起作用,那就太棒了。
这是Procfile:
web: gunicorn suacm.wsgi
web: gunicorn suacm:app当我使用这个命令运行app时,我的应用程序运行良好,并在本地运行:
gunicorn suacm.wsgi:application但我无法解决部署应用程序中的错误。
使用
heroku logs --tail我收到的错误如下所示:
2021-05-21T14:32:20.000000+00:00 app[api]: Build succeeded
2021-05-21T14:32:26.505788+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=suacm.herokuapp.com request_id=dfeba2ff-fa7d-4dfb-9337-706f50d286dc fwd="82.222.237.15" dyno= connect= service= status=503 bytes= protocol=https
2021-05-21T14:32:26.882608+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=suacm.herokuapp.com request_id=292525ae-bc4e-49c7-b979-e455bbfd6b95 fwd="82.222.237.15" dyno= connect= service= status=503 bytes= protocol=https当我运行这个
heroku ps:scale web=1 --app suacm我明白了:
Scaling dynos... !
▸ Couldn't find that process type (web).最后,当我尝试使用以下命令在src文件夹下本地运行heroku时
src % heroku local web我得到了这样的回应:
[INFO] Starting gunicorn 20.1.0
[INFO] Listening at: http://0.0.0.0:5000 (35246)
[INFO] Using worker: sync
[INFO] Booting worker with pid: 35247
Failed to find attribute 'app' in 'suacm'.
[INFO] Worker exiting (pid: 35247)
.
.如果需要,这是我的requirements.txt文件:
django_environ==0.4.5
djangorestframework_simplejwt==4.6.0
django_filter==2.4.0
Django==3.1.3
djangorestframework==3.12.4
environ==1.0
PyJWT==2.1.0
gunicorn==20.1.0
django-on-heroku==1.1.2
whitenoise==5.2.0这是我第一次部署django应用程序。我希望我能提供足够的信息。只要问一下是否需要更多的信息。
发布于 2021-05-22 03:59:44
将Procfile放在根目录中,而不是src和
改变这个
web: gunicorn suacm.wsgi至
web: gunicorn src.suacm.wsgi那么为什么它能在本地服务器上工作呢?
在本地设置中,您将从不是根目录的src目录启动服务器!
但是,在生产中,Heroku从根目录启动应用程序,因为根目录中没有Procfile,因此您将得到这些错误。
https://stackoverflow.com/questions/67637211
复制相似问题