连接mysql数据库,创建用户模型

 1 from flask import Flask
 2 from flask_sqlalchemy import SQLAlchemy
 3 import config
 4 
 5 app=Flask(__name__)
 6 app.config.from_object(config)
 7 db=SQLAlchemy(app)
 8 
 9 class User(db.Model):
10     __tablename__='user'
11     id=db.Column(db.Integer,primary_key=TabError,autoincrement=True)
12     username=db.Column(db.String(20),nullable=False)
13     password=db.Column(db.String(20),nullable=False)
14 
15 db.create_all()
16 
17 
18 
19 
20 @app.route('/')
21 def hello_world():
22     return 'hello World'
23 
24 
25 if __name__ == '__main__':
26       app.run()
1 SQLALCHEMY_DATABASE_URI='mysql+pymysql://root:@localhost:3306/test?charset=utf8'
2 SQLALCHEMY_TRACK_MODIFICATIONS=False

 

posted @ 2017-11-14 09:49  013洪辉  阅读(134)  评论(0编辑  收藏  举报