gpt4 book ai didi

python - 无法在 Heroku 上上传我的 flask 应用程序

转载 作者:太空宇宙 更新时间:2023-11-04 03:36:11 36 4
gpt4 key购买 nike

我有一个带有 postgresql db 的 flask 应用程序所以步骤是:

1.gunicorn
2.Procfile
3.heroku login
4.heroku apps:create flask-lili
5.heroku addons:add heroku-postgresql:dev
6.heroku pg:promote HEROKU_POSTGRESQL_ORANGE_URL
7.sudo pip install psycopg2
8.pip freeze> requirements.txt
10.git add .
11.git commit -m "create requirements.txt"
12.git push origin master
13.git push heroku master
14.heroku open

当我运行命令 git push heroku master 时没有出现错误,但不确定我是否应该使用命令编号 5 和 6

过程文件:

web: gunicorn manage:app
init: python manage.py db init
upgrade: python manage.py db upgrade
migrate: python manage.py db migrate

配置文件:

class Config(object):
DEBUG = False
SECRET_KEY = 'Thisismysecretkey'
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL',
'postgresql+psycopg2://peg:1234@localhost/app')
print SQLALCHEMY_DATABASE_URI


class TestingConfig(Config):
DEBUG = True
TESTING = True
PRESERVE_CONTEXT_ON_EXCEPTION = False
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL',
'postgresql+psycopg2://peg:1234@localhost/testapp')
print SQLALCHEMY_DATABASE_URI


class DevelopmentConfig(Config):
DEBUG = True


class ProductionConfig(Config):
DEBUG = False


config = {
'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig,
'default': DevelopmentConfig}

错误:

An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

谢谢你能帮我现在我运行命令 heroku logs --tail:

2015-03-09T12:17:29.670249+00:00 heroku[api]: Enable Logplex by peg@gmail.com
2015-03-09T12:17:29.670286+00:00 heroku[api]: Release v2 created by peg1@gmail.com
2015-03-09T12:21:36.990904+00:00 heroku[web.1]: Starting process with command `gunicorn manage:app`
2015-03-09T12:21:38.880134+00:00 app[web.1]: bash: gunicorn: command not found

即使我的需求中有 gunicorn

如果我运行“heroku run init”会出现错误:

File "manage.py", line 3, in <module>
from flask.ext.migrate import Migrate, MigrateCommand
ImportError: No module named flask.ext.migrate

我可以在本地无错误地运行应用程序,并且我在 requirements.txt 中有 flask-migrate

最佳答案

flask.ext 已弃用
将 flask.ext.migrate 更改为 flask_migrate 因此代码行变为

from flask_migrate import Migrate, MigrateCommand

代替

from flask.ext.migrate import Migrate, MigrateCommand

引用这个文档
Flask-迁移
https://flask-migrate.readthedocs.io/en/latest/

关于python - 无法在 Heroku 上上传我的 flask 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28942513/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com