本文介绍了Flask App在heroku上失败,但与领班合作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Heroku部署一个相当基本的应用程序,之前我已经成功了,但由于某种原因,现在我正在尝试导入一个导入错误。工头开始工作没有问题,但是当我尝试启动应用程序,似乎发生的事情,打破进口。这是我得到的日志消息:
$ b $ $ p $ heroku [web.1]:使用命令python manage.py runserver - p40309`
app [web.1]:追溯(最近一次调用最后):
app [web.1]:在< module>文件中的manage.py
app [web.1]:ImportError:没有模块名为SpoolEngine
app [web.1]:从SpoolEngine导入应用程序
heroku [web.1]:进程退出状态1
heroku [web.1]:状态从开始更改为崩溃
heroku [router]:at =错误代码= H10 desc =应用程序崩溃方法= GET路径= /主机=宁静泰加-1563。 herokuapp.com fwd =66.31.20.171dyno = connect = service = status = 503 bytes =
heroku [router]:at = error code = H10 desc =App crashedmethod = GET path = / favicon。 ico host = tranquil-taiga-1563.herokuapp.com fwd =66.31.20.171dyno = connect = service = status = 503 bytes =

这是我的Procfile:

  web:python manage.py runserver -p $ PORT 

这是 manage.py 文件I

  import os,sys 
sys.path.append(os.path。 abspath(os.path.join(os.path.dirname(__ file__),'..')))

from flask.ext.script import Manager,Serve从SpoolEngine导入应用程序

经理(应用程序)

manager.add_command(runserver,服务器(
use_debugger = True,
use_reloader = True,
host ='0.0.0.0')

$ b $ if if __name__ ==__main__:
manager.run()

对不起,如果这是我做的傻事,但我很新这个领域,并会真正欣赏一些指针。

解决方案

在这里猜测:您的代码显示

  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__ file__),'..')))

所以在本地你在manage.py的父目录中安装了一些软件包,但在Heroku中并不是这样。



只是为了调试,我还要添加

  import sys 
print sys.path

置于manage.py最顶端,并比较输出。您可以在本地运行的输出中查找您的模块,然后 heroku运行bash 并查看远程运行打印的目录中的内容。


I'm trying to deploy a fairly basic app with Heroku, and I've been successful before, but for some reason I'm getting an import error when I try now. Foreman start works with no issues, but when I try to start the application up, something seems to happen that breaks imports. This is the log message I get:

heroku[web.1]: Starting process with command `python manage.py runserver -p 40309`
app[web.1]: Traceback (most recent call last):
app[web.1]:   File "manage.py", line 6, in <module>
app[web.1]: ImportError: No module named SpoolEngine
app[web.1]:     from SpoolEngine import app
heroku[web.1]: Process exited with status 1
heroku[web.1]: State changed from starting to crashed
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=tranquil-taiga-1563.herokuapp.com fwd="66.31.20.171" dyno= connect= service= status=503 bytes=
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=tranquil-taiga-1563.herokuapp.com fwd="66.31.20.171" dyno= connect= service= status=503 bytes=

This is my Procfile:

web: python manage.py runserver -p $PORT

and this is the manage.py file I'm using to start everything up:

import os, sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from flask.ext.script import Manager, Server
from SpoolEngine import app

manager = Manager(app)

manager.add_command("runserver", Server(
    use_debugger=True,
    use_reloader=True,
    host='0.0.0.0')
)

if __name__ == "__main__":
    manager.run()

I'm sorry if this is something silly that I've done, but I'm pretty new to this realm and would really appreciate some pointers.

解决方案

Guessing here: your code shows

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

So locally you have some packages installed in manage.py's parent directory, but that's not the case in Heroku.

Just to debug, I would also add

import sys
print sys.path

to the very top of manage.py, and compare outputs. You can look for your modules in the output of the local run, and then heroku run bash and look at what's in the directories printed by the remote run.

这篇关于Flask App在heroku上失败,但与领班合作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 05:04