flask SQLAlchemy 入门示例
#coding=utf-8 from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy app = Flask(__name__) app.config[‘SQLALCHEMY_DATABASE_URI‘] = ‘sqlite:///D:/code/t/src/app.db‘ db = SQLAlchemy(app) class User(db.Model): id = db.Column(db.Integer, primary_key = True) user_name = db.Column(db.String(30)) def __init__(self, id, user_name): self.id = id self.user_name = user_name def __repr__(self): return ‘<User %r>‘ % self.user_name @app.route(‘/‘) def index(): return ‘flask‘ if __name__ == ‘__main__‘: db.create_all() app.run(port = 80)
本文出自 “自由自我” 博客,请务必保留此出处http://hhuayuan.blog.51cto.com/1630327/1582224
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。