簡體   English   中英

為什么我的Django應用程序在本地工作,而不是在Heroku上工作?

[英]Why does my Django app work locally, but not on Heroku?

我的Django應用程序在本地工作正常,有時推送到Heroku是成功的,但heroku日志顯示錯誤(並且應用程序不會在線加載)。 似乎我的Procfile(或者也許是我的virtualenv)有問題,盡管我已經重新做了整件事以試圖解決這個問題。

我在我的Procfile中嘗試了很多這個版本:

web: python manage.py collectstatic --noinput; bin/gunicorn_django --workers=4 --bind=0.0.0.0:$PORT proj/prod_settings.py

和這個:

web: python manage.py runserver 0.0.0.0:$PORT collectstatic --noinput
--settings=proj/prod_settings.py

和這個:

web: gunicorn bookfairy.wsgi.py

但我不斷收到這樣的錯誤:

-foreman start pid 17199 result: no such option: --noinput

-foreman start pid 17229 result: no such option: --workers

-foreman start pid 17299 result: Could not import settings 'proj/prod_settings.py' (Is it on sys.path?): Import by filename is not supported.
-Push failed: slug archive could not be created
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to heroku
-foreman start pid 16943 result: Error: Usage is runserver [optional port number, or ipaddr:port]
-Process exited with status 1
State changed from starting to crashed
-heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/robots.txt     host=bookfairy.herokuapp.com fwd="66.249.72.200" dyno= connect= service= status=503 bytes=
-heroku[router]: at=error code=H14 desc="No web processes running" method=GET path=/robots.txt host=bookfairy.herokuapp.com fwd="173.199.115.131" dyno= connect= service= status=503 bytes=

和這個:

    File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
    return self.handle_noargs(**options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/__init__.py", line 317, in cursor
    cursor = self.make_debug_cursor(self._cursor())
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
    self.connection = Database.connect(**conn_params)
  File "/app/.heroku/python/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

我能想到的事情我嘗試過:

  • 刪除並替換我的Procfile(大寫,是)
  • 完成pip凍結到我的requirements.txt文件
  • 添加了runtime.txt文件
  • 開始了一個dyno
  • 遵循所有Heroku Django指令
  • 重新安排我的目錄結構(並將我的wsgi.py文件移動到與requirements.txt相同的文件夾)
  • 試過run_gunicorn(未知命令錯誤)
  • pip安裝了所有依賴項(兩次,包括Django,psycopg2,dj-database-url)
  • heroku運行python manage.py syncdb(服務器是否在主機“localhost”(127.0.0.1)上運行並接受端口5432上的TCP / IP連接?)
  • 檢查Postgres和Heroku工具帶安裝

我非常感謝能得到一些幫助。

命令python manage.py runserver 0.0.0.0:$PORT collectstatic --noinput無效,你試圖在一個中做兩件事。

python manage.py runserver 0.0.0.0:$PORT

python manage.py collectstatic --noinput

將它們分開作為單獨的命令,我建議將runserver放在Procfile中並在shell中運行collectstatic

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM