# 安装后可直接在py中使用
import flask
from flask.ext.sqlalchemy import SQLAlchemy
app = flask.Flask(__name__)
# - Settings里配置了SqlAlchemy的
数据库地址
#
sqlite ex: "sqlite:///dbname.db"
app.config.from_object("Settings")
db = SQLAlchemy(app)
db.init_app(app)
# - create_all() 调用时将会创建所有继承db.Model的模版
# Model ex: 见 Class AdminInfo
db.create_all()
class AdminInfo(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(16))
password = db.Column(db.String(32))
kidname = db.Column(db.String(16))
diy_show = db.Column(db.Text)
def __init__(self, name, password, kidname, diy_show):
self.name = name
self.password = password
self.kidname = kidname
self.diy_show = diy_show
def __repr__(self):
return "<name: %s pw: %s>"%(self.name, '*'*len(self.password))