connecting to database using sqlalchemy using DATABASE_URL

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-11 15:59:41

问题


I am comfortable in using SQL query languages and need to develop a web application. I am learning python -sqlachemy and stuck in get connected to postgressql database.

Please let me know: what are the libraries i need to install ? How do i Configure DATABASE_URL in flask.[enter image description here][1]

I am stuck with code line no-6. I need to know how to get DATABASE_URL configured? I am very new potgressql. [1]: https://i.stack.imgur.com/7oGRC.png


回答1:


You can set it up in bash or you can use dotenv package from pypi:

$ export DATABASE_URL=postgresql://username:password@host:port/dbname

If your username=blue, password=pass, host=localhost, and port=5432, dbname=testDB then:

$ export DATABASE_URL=postgresql://blue:pass@localhost:5432/testDB

To check if the postgres db is running-- or check the port on which it is running:

$ sudo lsof -i -n -P | grep LISTEN


来源:https://stackoverflow.com/questions/62768498/connecting-to-database-using-sqlalchemy-using-database-url

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