微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

部署 Django 应用程序时 Heroku 中的应用程序错误,具体而言,日志尾部显示 = 构建失败 -- 检查您的构建输出:*link*

如何解决部署 Django 应用程序时 Heroku 中的应用程序错误,具体而言,日志尾部显示 = 构建失败 -- 检查您的构建输出:*link*

这是我第一次在 Heroku 中部署 Django 应用程序,我正在关注一篇关于 git push 和所有其他任务的文章。当我开始推送 master 时,问题就开始了。我的应用没有加载。因此,从 Heroku 文档中,我将推送移至 main 并删除了 master。出现了一个新问题,即应用程序错误,并要求 Heroku log --tails。后来我发现 procfile 没有正确的应用程序名称。纠正了这个问题并重新启动了 Heroku。尽管如此,它还是显示一个应用程序错误,其中红色的行说:构建失败——检查你的构建输出https://dashboard.heroku.com/apps/6609d304-92ca-454e-8659-561a8adbb11a/activity/builds/6c1dd096-0d90-49af-a5db-55eec4dff27b获取 Heroku 日志 --tail。

终端:Heroku 日志 --tail

 (env) D:\DJPROJ\OFFSET_V1.1\v1>heroku logs --tail
2021-05-30T08:27:39.043493+00:00 app[api]: Initial release by user aera4242@gmail.com
2021-05-30T08:27:39.043493+00:00 app[api]: Release v1 created by user aera4242@gmail.com
2021-05-30T08:27:39.615588+00:00 app[api]: Enable Logplex by user aera4242@gmail.com
2021-05-30T08:27:39.615588+00:00 app[api]: Release v2 created by user aera4242@gmail.com
2021-05-30T08:33:03.000000+00:00 app[api]: Build started by user aera4242@gmail.com
2021-05-30T08:33:32.000000+00:00 app[api]: Build Failed -- check your build output: https://dashboard.heroku.com/apps/6609d304-92ca-454e-8659-561a8adbb11a/activity/builds/bb5f0314-a49e-4e29-b6a0-1ec421b92733
2021-05-30T08:47:08.146897+00:00 app[api]: Starting process with command `python manage.py migrate` by user aera4242@gmail.com
2021-05-30T08:47:08.852782+00:00 heroku[run.2613]: State changed from starting to up
2021-05-30T08:47:09.202077+00:00 heroku[run.2613]: Awaiting client
2021-05-30T08:47:09.491181+00:00 heroku[run.2613]: Starting process with command `python manage.py migrate`
2021-05-30T08:47:13.897745+00:00 heroku[run.2613]: Process exited with status 2
2021-05-30T08:47:13.966147+00:00 heroku[run.2613]: State changed from up to complete
2021-05-30T08:48:00.087012+00:00 app[api]: Starting process with command `python manage.py migrate` by user aera4242@gmail.com
2021-05-30T08:48:00.790244+00:00 heroku[run.1873]: State changed from starting to up
2021-05-30T08:48:01.143261+00:00 heroku[run.1873]: Awaiting client
2021-05-30T08:48:01.338490+00:00 heroku[run.1873]: Starting process with command `python manage.py migrate`
2021-05-30T08:48:06.187945+00:00 heroku[run.1873]: Process exited with status 2
2021-05-30T08:48:06.262165+00:00 heroku[run.1873]: State changed from up to complete
2021-05-30T08:48:59.949192+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/" host=off1.herokuapp.com request_id=b4b4fa2e-4252-4bf4-a744-2e5c2bdab4a1 fwd="115.42.52.162" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T08:49:00.332156+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=23ad728e-9951-488c-b5cd-6e97f500012b fwd="115.42.52.162" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T08:49:11.727981+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/" host=off1.herokuapp.com request_id=153f1949-1d42-43ce-9ba5-168e3069ea76 fwd="115.42.52.162" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T08:49:12.395135+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=bd0a3aa1-7634-4956-9c17-5b63c25e5e79 fwd="115.42.52.162" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T08:50:40.502949+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/" host=off1.herokuapp.com request_id=c9740535-9ef9-442a-9131-3579e64865c7 fwd="115.42.52.166" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T08:50:40.818555+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=33792eca-5ab4-46cb-8832-a8e3d9f73ffe fwd="115.42.52.166" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T08:51:18.804650+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/" host=off1.herokuapp.com request_id=2f85bf4d-81f9-4519-a31b-27989571c47d fwd="115.42.52.166" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T08:51:19.454601+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=4f88548a-8aa8-4652-aa5d-bdfdea45da6a fwd="115.42.52.166" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T08:52:29.000000+00:00 app[api]: Build started by user aera4242@gmail.com
2021-05-30T08:52:59.000000+00:00 app[api]: Build Failed -- check your build output: https://dashboard.heroku.com/apps/6609d304-92ca-454e-8659-561a8adbb11a/activity/builds/6c1dd096-0d90-49af-a5db-55eec4dff27b
2021-05-30T09:01:35.511449+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/" host=off1.herokuapp.com request_id=ff64308b-4f51-4837-9ce2-a23ab2d7a809 fwd="115.42.52.190" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T09:01:35.963136+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=95c7a49e-4b3f-4fab-b362-e5ea601e69b7 fwd="115.42.52.190" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T09:21:58.481667+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/" host=off1.herokuapp.com request_id=778bb534-9993-4fb4-aa6b-955aad309398 fwd="115.42.52.174" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T09:21:58.896278+00:00 heroku[router]: at=info code=H81 desc="Blank app" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=6a91f74b-dc4a-4d13-983b-f955afee431a fwd="115.42.52.174" dyno= connect= service= status=502 bytes= protocol=https
2021-05-30T09:27:45.624223+00:00 app[api]: Starting process with command `bundle exec rake db:migrate` by user aera4242@gmail.com
2021-05-30T09:27:46.335939+00:00 heroku[run.9651]: State changed from starting to up
2021-05-30T09:27:46.763198+00:00 heroku[run.9651]: Awaiting client
2021-05-30T09:27:47.072227+00:00 heroku[run.9651]: Starting process with command `bundle exec rake db:migrate`
2021-05-30T09:27:51.728869+00:00 heroku[run.9651]: Process exited with status 127
2021-05-30T09:27:51.815954+00:00 heroku[run.9651]: State changed from up to complete
2021-05-30T09:29:28.655372+00:00 app[api]: Set disABLE_COLLECTSTATIC config vars by user aera4242@gmail.com
2021-05-30T09:29:28.655372+00:00 app[api]: Release v3 created by user aera4242@gmail.com
2021-05-30T09:38:27.000000+00:00 app[api]: Build started by user aera4242@gmail.com
2021-05-30T09:39:09.302528+00:00 app[api]: Attach DATABASE (@ref:postgresql-aerodynamic-89722) by user aera4242@gmail.com
2021-05-30T09:39:09.302528+00:00 app[api]: Running release v4 commands by user aera4242@gmail.com
2021-05-30T09:39:09.316993+00:00 app[api]: @ref:postgresql-aerodynamic-89722 completed provisioning,setting DATABASE_URL. by user aera4242@gmail.com
2021-05-30T09:39:09.316993+00:00 app[api]: Release v5 created by user aera4242@gmail.com
2021-05-30T09:39:09.608803+00:00 app[api]: Release v6 created by user aera4242@gmail.com
2021-05-30T09:39:09.608803+00:00 app[api]: Deploy 9fdb0adf by user aera4242@gmail.com
2021-05-30T09:39:21.000000+00:00 app[api]: Build succeeded
2021-05-30T09:40:01.457261+00:00 app[api]: Starting process with command `python manage.py migrate` by user aera4242@gmail.com
2021-05-30T09:40:07.745943+00:00 heroku[run.6735]: State changed from starting to up
2021-05-30T09:40:07.896324+00:00 heroku[run.6735]: Awaiting client
2021-05-30T09:40:07.927791+00:00 heroku[run.6735]: Starting process with command `python manage.py migrate`
2021-05-30T09:40:14.939487+00:00 heroku[run.6735]: Process exited with status 0
2021-05-30T09:40:14.993471+00:00 heroku[run.6735]: State changed from up to complete
2021-05-30T09:40:32.197329+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=off1.herokuapp.com request_id=a8adc809-f9fe-43f2-9516-19adc21b4e81 fwd="115.42.52.164" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T09:40:32.885137+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=9a717a13-cbeb-4ae0-b5e6-c706116780b0 fwd="115.42.52.164" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T09:40:57.425964+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=off1.herokuapp.com request_id=191b4cb8-7c70-4c13-9542-55783a5cc4bc fwd="115.42.52.164" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T09:40:58.000926+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=cd788777-1937-448e-b360-3b5d1687474c fwd="115.42.52.164" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T09:49:27.525495+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=off1.herokuapp.com request_id=fb7aa6aa-a887-4ff1-8876-08adfb6c33f6 fwd="115.42.52.168" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T09:49:27.895519+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=703001d5-5fe9-429e-b35f-96151496f20f fwd="115.42.52.168" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T09:55:26.756267+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=off1.herokuapp.com request_id=f62c6dfb-2664-4563-a0c5-59cfb85b93aa fwd="115.42.52.186" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T09:55:27.341312+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=a21e6734-93c9-4ec7-95d3-028444066a7e fwd="115.42.52.186" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T09:56:42.266521+00:00 app[api]: Starting process with command `rake db:migrate` by user aera4242@gmail.com
2021-05-30T09:56:48.475979+00:00 heroku[run.8708]: State changed from starting to up
2021-05-30T09:56:48.833282+00:00 heroku[run.8708]: Awaiting client
2021-05-30T09:56:48.866252+00:00 heroku[run.8708]: Starting process with command `rake db:migrate`
2021-05-30T09:56:53.682754+00:00 heroku[run.8708]: Process exited with status 1
2021-05-30T09:56:53.742473+00:00 heroku[run.8708]: State changed from up to complete
2021-05-30T09:56:59.829131+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=off1.herokuapp.com request_id=23aa5296-7929-4870-88e2-fcc3528a3a37 fwd="115.42.52.163" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T09:57:00.390160+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=9eb3d4dd-c953-44a6-9d99-292ebec17f28 fwd="115.42.52.163" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T10:23:11.421610+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=off1.herokuapp.com request_id=ceeebec1-3988-49c4-9265-373f765fe511 fwd="115.42.52.176" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T10:23:11.999647+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=ec7196ff-4911-4b9e-be79-e06ff615ca0d fwd="115.42.52.176" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T10:26:57.666756+00:00 app[api]: Starting process with command `python manage.py migrate` by user aera4242@gmail.com
2021-05-30T10:27:04.616979+00:00 heroku[run.6908]: State changed from starting to up
2021-05-30T10:27:04.986280+00:00 heroku[run.6908]: Awaiting client
2021-05-30T10:27:05.008738+00:00 heroku[run.6908]: Starting process with command `python manage.py migrate`
2021-05-30T10:27:11.505688+00:00 heroku[run.6908]: Process exited with status 0
2021-05-30T10:27:11.561616+00:00 heroku[run.6908]: State changed from up to complete
2021-05-30T10:27:17.269386+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=off1.herokuapp.com request_id=66ce0137-2553-4739-861e-7dae66601309 fwd="115.42.52.179" dyno= connect= service= status=503 bytes= protocol=https
2021-05-30T10:27:17.884489+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=off1.herokuapp.com request_id=3b51efa3-ba6a-4f83-ad69-309e6907c8b5 fwd="115.42.52.179" dyno= connect= service= status=503 bytes= protocol=https
 

红线

https://dashboard.heroku.com/apps/6609d304-92ca-454e-8659-561a8adbb11a/activity/builds/6c1dd096-0d90-49af-a5db-55eec4dff27b

直接链接给出了这个

-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
-----> Python app detected
-----> No Python version was specified. Using the buildpack default: python-3.9.5
       To use a different version,see: https://devcenter.heroku.com/articles/python-runtimes
-----> Installing python-3.9.5
-----> Installing pip 20.2.4,setuptools 47.1.1 and wheel 0.36.2
-----> Installing sqlite3
-----> Installing requirements with pip
       Collecting asgiref==3.3.4
         Downloading asgiref-3.3.4-py3-none-any.whl (22 kB)
       Collecting dj-database-url==0.5.0
         Downloading dj_database_url-0.5.0-py2.py3-none-any.whl (5.5 kB)
       Collecting Django==3.2.3
         Downloading Django-3.2.3-py3-none-any.whl (7.9 MB)
       Collecting django-heroku==0.3.1
         Downloading django_heroku-0.3.1-py2.py3-none-any.whl (6.2 kB)
       Collecting gunicorn==20.1.0
         Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
       Collecting psycopg2==2.8.6
         Downloading psycopg2-2.8.6.tar.gz (383 kB)
       Collecting pytz==2021.1
         Downloading pytz-2021.1-py2.py3-none-any.whl (510 kB)
       Collecting sqlparse==0.4.1
         Downloading sqlparse-0.4.1-py3-none-any.whl (42 kB)
       Collecting whitenoise==5.2.0
         Downloading whitenoise-5.2.0-py2.py3-none-any.whl (19 kB)
       Building wheels for collected packages: psycopg2
         Building wheel for psycopg2 (setup.py): started
         Building wheel for psycopg2 (setup.py): finished with status 'done'
         Created wheel for psycopg2: filename=psycopg2-2.8.6-cp39-cp39-linux_x86_64.whl size=523855 sha256=b093f427ebabaf501fa8e5ed90d25c8d623b2bc34ed054a20691960d0aa574c5
         Stored in directory: /tmp/pip-ephem-wheel-cache-vk7w3af4/wheels/a2/07/10/a9a82e72d50feb8d646acde6a88000bbf2ca0f82e41aea438a
       Successfully built psycopg2
       Installing collected packages: asgiref,dj-database-url,sqlparse,pytz,Django,psycopg2,whitenoise,django-heroku,gunicorn
       Successfully installed Django-3.2.3 asgiref-3.3.4 dj-database-url-0.5.0 django-heroku-0.3.1 gunicorn-20.1.0 psycopg2-2.8.6 pytz-2021.1 sqlparse-0.4.1 whitenoise-5.2.0
-----> $ python manage.py collectstatic --noinput
       Traceback (most recent call last):
         File "/tmp/build_3b53899d/manage.py",line 22,in <module>
           main()
         File "/tmp/build_3b53899d/manage.py",line 18,in main
           execute_from_command_line(sys.argv)
         File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py",line 419,in execute_from_command_line
           utility.execute()
         File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py",line 413,in execute
           self.fetch_command(subcommand).run_from_argv(self.argv)
         File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py",line 354,in run_from_argv
           self.execute(*args,**cmd_options)
         File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py",line 398,in execute
           output = self.handle(*args,**options)
         File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",line 187,in handle
           collected = self.collect()
         File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",line 105,in collect
           for path,storage in finder.list(self.ignore_patterns):
         File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/finders.py",line 130,in list
           for path in utils.get_files(storage,ignore_patterns):
         File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/utils.py",line 23,in get_files
           directories,files = storage.listdir(location)
         File "/app/.heroku/python/lib/python3.9/site-packages/django/core/files/storage.py",line 323,in listdir
           for entry in os.scandir(path):
       FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_3b53899d/static'
 !     Error while running '$ python manage.py collectstatic --noinput'.
       See traceback above for details.
       You may need to update the application code to resolve this error.
       Or,you can disable collectstatic for this application:
          $ Heroku config:set disABLE_COLLECTSTATIC=1
       https://devcenter.heroku.com/articles/django-assets
 !     Push rejected,Failed to compile Python app.
 !     Push Failed

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE','v1.settings')

application = get_wsgi_application()

ma​​nage.py

import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE','v1.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

procfile

web: gunicorn v1.wsgi

Requirement.txt

asgiref==3.3.4
dj-database-url==0.5.0
Django==3.2.3
django-heroku==0.3.1
gunicorn==20.1.0
psycopg2==2.8.6
pytz==2021.1
sqlparse==0.4.1
whitenoise==5.2.0

文件

-v1
  -home
    -migrations
    -static
    -templates
    -__init__.py
    -admins.py
    -models.py
    -apps.py
    -urls.py
    -tests.py
    -views.py
  -static                            *edited this portion as per comment*
  -v1
    -__init__.py
    -asgi.py
    -settings.py
    -wsgi.py
    -urls.py
  -manage.py
  -procfile.file
  -requirements.txt
  -dbsqlite3

STATICFILES_Dirs

STATICFILES_Dirs =  [
    os.path.join(BASE_DIR,'static')
]
STATIC_URL = '/static/'

编辑文件树后,Heroku 中的状态显示“构建成功”和“已部署”。运行应用程序时仍然存在应用程序错误https://off1.herokuapp.com/

最新构建日志

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/python
-----> Python app detected
-----> No Python version was specified. Using the same version as the last build: python-3.9.5
       To use a different version,see: https://devcenter.heroku.com/articles/python-runtimes
-----> No change in requirements detected,installing from cache
-----> Using cached install of python-3.9.5
-----> Installing pip 20.2.4,setuptools 47.1.1 and wheel 0.36.2
-----> Installing sqlite3
-----> Installing requirements with pip
-----> Skipping Django collectstatic since the env var disABLE_COLLECTSTATIC is set.
-----> discovering process types
       procfile declares types -> (none)
-----> Compressing...
       Done: 60.4M
-----> Launching...
       Released v7
       https://off1.herokuapp.com/ deployed to Heroku

我真的很困惑,需要一个易于理解的解决方案来修复应用程序错误。感谢!

解决方法

CheckAbdul Aziz Barkat 在评论部分指导我之后,这个门户似乎对我的问题有明确的解决方案。

  • 我不得不在settings.py文件中添加这两行

    STATIC_ROOT = os.path.join(BASE_DIR,"staticfiles") STATICFILES_STORAGE='whitenoise.django.GzipManifestStaticFilesStorage'

  • 在项目的 static 文件夹中添加了一个空白的 txt 文件或任何内容。这有助于 git add

  • 仅将 Procfile.file 重命名为 Procfile

  • 删除之前的requirements.txt文件并再次运行cmd行,pip freeze > requirements.txt

  • git add . -> git status -> git commit -m "..." -> git push heroku main

这对我的 Django 项目非常有效,可以获得完美的部署和视图。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。