问题
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