Python database WITHOUT using Django (for Heroku)

前端 未结 4 464
误落风尘
误落风尘 2021-02-02 15:54

To my surprise, I haven\'t found this question asked elsewhere. Short version, I\'m writing an app that I plan to deploy to the cloud (probably using Heroku), which will do var

4条回答
  •  死守一世寂寞
    2021-02-02 16:43

    I did this recently with Flask. (https://github.com/HexIce/flask-heroku-sqlalchemy).

    There are a couple of gotchas:

    1. If you don't use Django you may have to set up your database yourself by doing:

    heroku addons:add shared-database
    

    (Or whichever database you want to use, the others cost money.)

    2. The database URL is stored in Heroku in the "DATABASE_URL" environment variable. In python you can get it by doing.

    dburl = os.environ['DATABASE_URL']
    

    What you do to connect to the database from there is up to you, one option is SQLAlchemy.

提交回复
热议问题