2015-12-29 27 views
-1

我有一个Flask应用程序,用Cloud9 IDE编写。我在本地运行它:终端中的“python manage.py runserver”。 这然后触发:Python,Flask:Heroku无法打开(并运行)应用程序

manager.add_command('runserver', Server(
    use_debugger = True, 
    use_reloader = True, 
    host = os.getenv('IP', '0.0.0.0'), 
    port = int(os.getenv('PORT', 5000)) 
    ) 
) 

这段代码位于manage.py文件。

现在我想用Heroku运行它。我完全按照他们的教程。我只是不知道我的Procfile应该是什么。我写的,像这样:

web: gunicorn manage:runserver 

推混帐等一切似乎很好地工作。 当我键入: “Heroku的PS:衡量Web = 1”,我在终端得到这样的:

Scaling dynos... done, now running web at 1:Free. 

当我键入 “Heroku的开放”,我得到这个错误:

Opening fierce-spire-3069... xprop: unable to open display '' 
xprop: unable to open display '' 
/usr/bin/xdg-open: 461: /usr/bin/xdg-open: links2: not found 
/usr/bin/xdg-open: 461: /usr/bin/xdg-open: links: not found 
/usr/bin/xdg-open: 461: /usr/bin/xdg-open: lynx: not found 
/usr/bin/xdg-open: 461: /usr/bin/xdg-open: w3m: not found 
xdg-open: no method available for opening 'https://fierce-spire-3069.herokuapp.com/' 
done 

所以,我的应用程序无法打开。 当我用Heroku网站打开它时,出现一条错误消息。这是我在原木中发现的:

2015-12-29T20:15:06.399443+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=fierce-spire-3069.herokuapp.com request_id=c5d76e45-5d56-45f4-a2bc-75bd7fc08b7f fwd="81.82.128.183" dyno= connect= service= status=503 bytes= 

我在做什么错?

编辑

我改变了我的个人资料如下:

web: python manage.py runserver "0.0.0.0:5000" 

在Heroku的日志中的上述错误消息已不存在,但有一个新问题:

2015-12-29T21:30:37.938957+00:00 app[web.1]:  from tsb import app 
2015-12-29T21:30:37.938955+00:00 app[web.1]: File "manage.py", line 7, in <module> 
2015-12-29T21:30:37.939002+00:00 app[web.1]: ImportError: No module named tsb 

这是指manage.py代码的这一部分:

from tsb import app 

“tsb”是存储我所有项目文件的文件夹,它是项目文件夹。为什么不能导入?

+0

不要在生产中使用内置的开发服务器,尤其是启用了调试器的情况下。 – davidism

+0

你是什么意思?我不知道该怎么做ImortError。 – Vincent

+0

我的意思是不要在生产中使用它,它既不安全也不高效。我没有评论导入错误。 – davidism

回答

2

您没有正确使用gunicorn。该basic usage

$ gunicorn [OPTIONS] APP_MODULE 

这是你需要在Procfile使用什么。

web: gunicorn [OPTIONS] APP_MODULE 

我不能告诉你使用什么选项。你可以在Heroku's gunicorn documentation中找到。这里重要的是APP_MODULE

它看起来像你的应用程序实例正在通过manage.py暴露,所以你想使用

web: gunicorn manage 

如果你试试这个,但是,它可能会失败。默认情况下,gunicorn将在APP_MODULE内寻找名为application的东西。您的应用程序似乎被命名为manager。这意味着您需要

web: gunicorn manage:manager 
+0

我想我没有使用gunicorn解决它,但现在我有一个新的错误..我编辑了我原来的问题。 – Vincent

+0

gunicorn不是你的问题。另外,你不应该在生产中使用开发服务器。 – dirn