diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..138a9ec --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,27 @@ + + + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:identifier.sqlite + $ProjectFileDir$ + + + sqlite.xerial + true + org.sqlite.JDBC + jdbc:sqlite:$PROJECT_DIR$/flask框架/instance/example.db + $ProjectFileDir$ + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/xerial/sqlite-jdbc/3.45.1.0/sqlite-jdbc-3.45.1.0.jar + + + file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.45.1/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index c675b1d..766247c 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,9 +3,7 @@ - - - + diff --git a/flask框架/flask数据库迁移/flask数据库迁移.py b/flask框架/flask数据库迁移/flask数据库迁移.py new file mode 100644 index 0000000..0569bb6 --- /dev/null +++ b/flask框架/flask数据库迁移/flask数据库迁移.py @@ -0,0 +1,47 @@ +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +from flask_migrate import Migrate + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///example.db' +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +db = SQLAlchemy(app) +migrate = Migrate(app, db) + + +class User(db.Model): + id = db.Column(db.Integer, primary_key=True) + username = db.Column(db.String(80), unique=True, nullable=False) + email = db.Column(db.String(120), unique=True, nullable=False) + gender = db.Column(db.String(10)) # 新增的性别列,可以为空 + ew_gender = db.Column(db.String(10)) # 新增的性别列,可以为空 + + def __repr__(self): + return f'' + + +# 初始化数据库并添加数据 +def init_db(): + with app.app_context(): + # 创建所有表 + db.create_all() + + # 检查是否已有数据,避免重复添加 + if not User.query.first(): + # 添加初始用户数据 + users = [ + User(username='john_doe', email='john@example.com'), + User(username='jane_smith', email='jane@example.com'), + User(username='bob_johnson', email='bob@example.com') + ] + + db.session.add_all(users) + db.session.commit() + print("初始数据已添加") + + +if __name__ == '__main__': + init_db() + print("数据库已初始化") + +migrate = Migrate(app, db) \ No newline at end of file diff --git a/flask框架/flask蓝图/app.py b/flask框架/flask蓝图/app.py new file mode 100644 index 0000000..e69de29 diff --git a/flask框架/flask蓝图/auth/__init__.py b/flask框架/flask蓝图/auth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/flask框架/flask蓝图/blog/__init__.py b/flask框架/flask蓝图/blog/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python.iml b/python.iml index fb086f4..d6a0489 100644 --- a/python.iml +++ b/python.iml @@ -10,9 +10,10 @@ + - + \ No newline at end of file