Python 404设置postgres数据库路径的问题
我一直在试图弄清楚我是如何将数据库路径格式化错误的。我尝试了许多不同的方法,但都返回了404Python 404设置postgres数据库路径的问题,python,database,sqlalchemy,http-status-code-404,psql,Python,Database,Sqlalchemy,Http Status Code 404,Psql,我一直在试图弄清楚我是如何将数据库路径格式化错误的。我尝试了许多不同的方法,但都返回了404 #models.py import os from sqlalchemy import Column, String, Integer, create_engine from flask_sqlalchemy import SQLAlchemy import json database_name = "trivia" database_path = "postgres://{}:{}@{}/{}".
#models.py
import os
from sqlalchemy import Column, String, Integer, create_engine
from flask_sqlalchemy import SQLAlchemy
import json
database_name = "trivia"
database_path = "postgres://{}:{}@{}/{}".format('postgres', 'password', 'localhost:5432', database_name)
db = SQLAlchemy()
def setup_db(app, database_path=database_path):
app.config["SQLALCHEMY_DATABASE_URI"] = database_path
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.app = app
db.init_app(app)
db.create_all()
我的数据库设置只是为了表明我已经设置好了,并且我的数据库名称实际上被称为“琐事”:
$ psql -U postgres
Password for user postgres:
psql (12.1)
WARNING: Console code page (437) differs from Windows code page (1252)
8-bit characters might not work correctly. See psql reference
page "Notes for Windows users" for details.
Type "help" for help.
postgres=# \c trivia
You are now connected to database "trivia" as user "postgres".
trivia=# \dt
List of relations
Schema | Name | Type | Owner
--------+------------+-------+----------
public | categories | table | postgres
public | questions | table | postgres
(2 rows)
trivia=# \d
List of relations
Schema | Name | Type | Owner
--------+-------------------+----------+----------
public | categories | table | postgres
public | categories_id_seq | sequence | postgres
public | questions | table | postgres
public | questions_id_seq | sequence | postgres
(4 rows)
感谢您的帮助您凭什么确定数据库连接有问题?如果数据库出现问题,我希望HTTP响应的状态代码为5xx(至少在开发模式下)。状态代码404可能表示在给定的URI中没有端点。@如果您愿意看一看,这里是我的git代表。我认为我的数据库有问题,因为没有任何东西要显示。您触发哪个API调用?