1、建立model類
app01/models.py
1 2 3 4 5 6 7 | |
2、注冊app
settings.py
1 2 3 4 5 6 7 8 9 | |
3、執行指令建立表
cmd> python manage.py makemigrations 生成源資訊,一個字典,位置:app01/migrations/0001_initial.py
cmd> python manage.py migrate 讀取生成的源資訊,去生成資料庫表
4、檢視
4.1、用navicat-SQLite工具檢視
4.2、用程式檢視
app01/admin.py
1 2 | |
浏覽器通路http://127.0.0.1:8000/admin/
點進去後就可以添加使用者
5、現在有一個使用者user1,登入成功後跳轉到index頁面,列出資料庫表裡的所有使用者資訊。
app01/views.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
urls.py
1 2 3 4 5 6 7 8 | |
templates/index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
浏覽器通路 http://127.0.0.1:8000/login/
登入成功後跳轉到 http://127.0.0.1:8000/index/,列出所有的剛才手動在頁面建立的使用者。
6、model添加資料
index.html
1 2 3 4 5 | |
views.py
1 2 3 4 5 6 7 8 9 10 11 | |
7、model删除資料
index.html
1 2 3 4 5 | |
views.py
1 2 3 4 5 6 | |
8、model更新資料
index.html
1 2 3 4 5 | |
views.py
1 2 3 4 5 6 | |
9、頁面驗證:
來自為知筆記(Wiz)
轉載于:https://www.cnblogs.com/daliangtou/p/5262872.html