質問編集履歴

1

database.pyのコードの掲載を失念したため追記しました。

2022/04/05 14:41

投稿

cartocchi_0609
cartocchi_0609

スコア0

test CHANGED
File without changes
test CHANGED
@@ -72,7 +72,23 @@
72
72
  self.member = member
73
73
 
74
74
  ```
75
+ ```database.py
76
+ from sqlalchemy import create_engine
77
+ from sqlalchemy.orm import scoped_session, sessionmaker
78
+ from sqlalchemy.ext.declarative import declarative_base
79
+ import os
75
80
 
81
+ databese_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'suito.db')
82
+ engine = create_engine('sqlite:///' + databese_file, convert_unicode=True, connect_args={"check_same_thread": False})
83
+ db_session = scoped_session(sessionmaker(autocommit=False,autoflush=False,bind=engine))
84
+ Base = declarative_base()
85
+ Base.query = db_session.query_property()
86
+
87
+
88
+ def init_db():
89
+ import models.models
90
+ Base.metadata.create_all(bind=engine)
91
+ ```
76
92
 
77
93
  ```index.html
78
94
  <!DOCTYPE html>