安裝工具包
和Django 不一樣的是,flask 不自帶根據(jù)數(shù)據(jù)庫(kù)表生成models.py的功能,需額外安裝一個(gè)pip包绎巨。
pip install flask-sqlacodegen
生成models.py
flask-sqlacodegen 'mysql+pymysql://root:password@localhost:3306/db_name' --tables users,user_auth --outfile "models.py" --flask
查看models.py
在上一步生成的目錄做祝,可以找到models.py
cat models.py
感興趣的朋友可以根據(jù)如下步驟砾省,練練手:
數(shù)據(jù)庫(kù)準(zhǔn)備
請(qǐng)參考 關(guān)于固定資產(chǎn)的數(shù)據(jù)庫(kù)表準(zhǔn)備工作
使用上述生成models.py 的步驟
截圖如下: warning內(nèi)容可以忽略
image.png
查看生成的models.py的內(nèi)容
image.png