markdown
#說明
上一篇 :Python Flask "hello world"和 主頁(一)
Python Flask css 樣式表(二)
這篇要說明建立資料庫,這裡有些地方要特別注意,在操作上。
#操作流程
##app.py
```
from flask import Flask ,render_template,url_for
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
db = SQLAlchemy(app) #連接SQL資料庫
class Todo(db.Model):
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.String(200), nullable=False)
completed = db.Column(db.Integer, default=0)
date_created = db.Column(db.DateTime, default=datetime.utcnow)
def __repr__(self):
return '' % self.id
@app.route('/')
def index():
return render_template('index.html')
if __name__ == "__main__":
app.run(debug=True)
```
##app.py 編寫好了後,在terminal 執行指令:
這邊非常重要,就是要在 terminal 依序執行指令
```
python
from app import db
db.create_all( )
exit( )
```
##Demo
完成後,會自動生成 test.db
Slots & Slots | Casino Dr.Mcd
回覆刪除Find your favorite slot machines in 삼척 출장마사지 the 김천 출장안마 most convenient and 경상북도 출장샵 convenient location in the 상주 출장안마 country, from the top slots and live dealer games 화성 출장안마 to the newest