Couldnt upload My flask application on Heroku

二次信任 提交于 2019-12-11 02:15:05

问题


I have a flask application with postgresql db So the steps are:

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

I got no error when I run command git push heroku master, But Not sure that should I use command number 5 and 6 or Not

the Procfile :

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

config.py:

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}

The error:

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.

Thanx if You could help me Now I run command 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

even though I have gunicorn in my requirements

if I run "heroku run init" will get error:

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

I can run the application locally with no errors and I have flask-migrate in requirements.txt


回答1:


flask.ext is deprecated
change flask.ext.migrate to flask_migrate hence code lines go as

from flask_migrate import Migrate, MigrateCommand

instead of

from flask.ext.migrate import Migrate, MigrateCommand

refer this documentation
Flask-Migrate
https://flask-migrate.readthedocs.io/en/latest/




回答2:


Try changing from

flask.ext.migrate import Migrate, MigrateCommand

To

flask_Migrate import Migrate, MigrateCommand


来源:https://stackoverflow.com/questions/28942513/couldnt-upload-my-flask-application-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!