[問題] django CVB CRUD

看板Python作者 (痛苦)時間4年前 (2020/10/06 01:55), 4年前編輯推噓2(205)
留言7則, 5人參與, 4年前最新討論串1/1
Django 最近在把從FVB改成CVB 有關資料庫 沒有使用正規modelform 完成CRUD 練習一個一個html <tr> <td> URL:path('aaa/',Flycargo_totals.as_view()) 當link aaa時 想從資料庫讀資料並顯示在aaa上 一直發生try不到資料而啟動except 當我把units 讀取資料庫.objects.all()給刪除 就可以顯示正常aaa.html 但沒有資料庫資料壓? 請問哪邊有錯誤? Q1.CVB 已經在判斷get / post分類而不要在try/except資料庫? Q2.WHY? 已經卡關兩天.. 謝謝回覆 class Flycargo_totala(View): def get(self, request): try: units = Flycargo_total_model.objects.all() x = units time = datetime.now() # context = locals() # for x in units: # context['t_code_name'] = x.m_code_name # context['t_company_name'] = x.m_company_name # context['t_first_date'] = x.m_first_day # context['t_last_date'] = x.m_last_day # context['t_ship_days'] = x.m_ship_day return render(request, 'flycargo_total.html', locals()) except: units = "讀取錯誤" print("========nook") return HttpResponse("no ok") -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.228.127.110 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1601920522.A.E93.html

10/06 08:12, 4年前 , 1F
.....把try拿掉 看看錯誤訊息是什麼
10/06 08:12, 1F
※ 編輯: jackjenny (36.228.127.110 臺灣), 10/06/2020 13:34:32

10/06 15:28, 4年前 , 2F
先學會把問題描述清楚…
10/06 15:28, 2F

10/06 16:14, 4年前 , 3F
可悲阿
10/06 16:14, 3F

10/06 19:17, 4年前 , 4F
痛苦
10/06 19:17, 4F

10/06 19:49, 4年前 , 5F
抱歉造成閱讀困難 參考1F做法 原來是QuerySet沒處理好
10/06 19:49, 5F

10/06 19:52, 4年前 , 6F
原本想在T處理Queryset 並且連續2個for迴圈取資料庫值
10/06 19:52, 6F

10/06 19:54, 4年前 , 7F
應該丟到T的QuerySet 要obj.屬性取值
10/06 19:54, 7F
文章代碼(AID): #1VUruAwJ (Python)
文章代碼(AID): #1VUruAwJ (Python)