看板 Python 關於我們 聯絡資訊
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
TuCH: .....把try拿掉 看看錯誤訊息是什麼 10/06 08:12
※ 編輯: jackjenny (36.228.127.110 臺灣), 10/06/2020 13:34:32
Hsins: 先學會把問題描述清楚… 10/06 15:28
jasonfghx: 可悲阿 10/06 16:14
CaptPlanet: 痛苦 10/06 19:17
jackjenny: 抱歉造成閱讀困難 參考1F做法 原來是QuerySet沒處理好 10/06 19:49
jackjenny: 原本想在T處理Queryset 並且連續2個for迴圈取資料庫值 10/06 19:52
jackjenny: 應該丟到T的QuerySet 要obj.屬性取值 10/06 19:54