问题:将Django项目部署到Heroku

2024-06-25 23:46:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试将django应用程序部署到heroku,但出现错误:

remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/python
remote: -----> App not compatible with buildpack: https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/python.tgz
remote:        More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !       Push rejected to tandt-online-webchat.
remote: 
To https://git.heroku.com/tandt-online-webchat.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: не удалось отправить некоторые ссылки в «https://git.heroku.com/tandt-online-webchat.git»

我做了所有需要的事情: git添加。 git commit-m“relize heroku vers 1” 当我推heroku master的时候,我得到了这个错误

我有所有需要的文件:Procfile和requirements.txt 在Procfile中,我有:web:gunicorn web_chat.wsgi和to requirements.txt,我输入pip freeze,然后舒尔我有什么gunicorn她

我做错了什么


Tags: httpsgitmastercomsourceherokuremote错误
3条回答

一个常见的错误是您的requirements.txt文件有误。另一个可能发生的错误是,你的承诺已经非常错误。为此,请在本地重新初始化git存储库。然后确保添加了requirements.txt文件。你可以跟我核对一下

git status

如果这仍然不起作用,请让我知道

remote: -----> $ python manage.py collectstatic --noinput
remote:        /tmp/build_61db1e8d/staticfiles
remote:        Post-processing 'css/base.css' failed!
remote:        Traceback (most recent call last):
remote:          File "/tmp/build_61db1e8d/manage.py", line 22, in <module>
remote:            main()
remote:          File "/tmp/build_61db1e8d/manage.py", line 18, in main
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
remote:            self.execute(*args, **cmd_options)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
remote:            output = self.handle(*args, **options)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 194, in handle
remote:            collected = self.collect()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 138, in collect
remote:            raise processed
remote:        whitenoise.storage.MissingFileError: The file 'css/web_chat_imgs/фон_д_к.png' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7f16d93bc3d0>.
remote:        The CSS file 'css/base.css' references a file which could not be found:
remote:          css/web_chat_imgs/фон_д_к.png
remote:        Please check the URL references in this CSS file, particularly any
remote:        relative paths which might be pointing to the wrong location.
remote: 
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote: 
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote: 
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote: 
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !       Push rejected to tandt-online-webchat.
remote: 
To https://git.heroku.com/tandt-online-webchat.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: не удалось отправить некоторые ссылки в «https://git.heroku.com/tandt-online-webchat.git»

谢谢,但我并不完全了解你。我的setings.py文件到此结束sam有什么问题吗

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
# STATIC_ROOT = BASE_DIR/ 'static'

STATICFILES_DIRS = [
    BASE_DIR/ 'asets',
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'

django_heroku.settings(locals())

是的,这是很多人面临的另一个问题。在settings.py文件中

STATIC_ROOT = os.path.join(BASE_DIR, "static")

这允许Heroku将静态文件存储在git存储库的“static”文件夹中。“设置”文件夹中必须已有静态url。否则:

STATIC_URL = '/static/

此外,如果你有任何其他问题,试着编辑你原来的问题,而不是问一个新的问题,因为这有时会扩展页面太多

相关问题 更多 >