This is a sample Python script.
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
Press Shift+F10 to execute it or replace it with your code.
Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
class Config:
ENV = ‘development’
DEBUG = True
SQLALCHEMY_DATABASE_URI =‘mysql+pymysql://root:root@127.0.0.1:3306/students?charset=utf8’
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
SQLALCHEMY_TRACK_MODIFICATIONS = True
SQLALCHEMY_ECHO = True
SECRET_KEY = ‘abcdasa’
app = Flask(name)
app.config.from_object(Config)
db = SQLAlchemy()
db.init_app(app)
class Student(db.Model):
tablename = ‘tb_student’
# 字段类型
# 字段类型
id = db.Column(db.Integer,autoincrement=True, primary_key=True,comment=‘用户名’)
name = db.Column(db.String(64), unique=True)
sex = db.Column(db.Boolean,default=True, comment=‘性别’)
age = db.Column(db.Integer,nullable=True,comment=‘年龄’)
email = db.Column(db.String(128),unique=True,comment=‘邮箱地址’)
money = db.Column(db.Numeric(8,2),default=0,comment=‘钱包’)
# 模型方法
def repr(self):
return “%s %s” % (self.id, self.name)
class Teacher(db.Model):
# 表结构声明
id = db.Column(db.Integer,primary_key=True, comment=‘ID’)
name = db.Column(db.String(64),unique=True,comment=‘姓名’)
option = db.Column(db.Enum(“讲师”,“助教”, “班主任”),default=“讲师”,comment=“角色”)
def repr(self):
return ‘Teacher:%s’ % self.name
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f’Hi, {name}’) # Press Ctrl+F8 to toggle the breakpoint.
Press the green button in the gutter to run the script.
if name == ‘main’:
with app.app_context():
db.create_all()
print_hi(‘PyCharm’)