Skip to content
เข้าสู่ระบบ

Class-Based Views

FeatureFBV (Function-Based)CBV (Class-Based)
โครงสร้างfunctionclass
HTTP methodsif/elif statementsแยก method ชัดเจน
Inheritanceไม่มีรองรับ
Mixinsไม่มีรองรับ
Readabilityง่ายสำหรับ simple viewsดีสำหรับ complex views
ReusabilityCopy/pasteInherit และ override

เมื่อไหร่ใช้อะไร

Section titled “เมื่อไหร่ใช้อะไร”
Use CaseRecommendation
Simple viewsFBV
CRUD operationsCBV (Generic Views)
Complex logic with inheritanceCBV
One-off custom logicFBV
REST APICBV + DRF ViewSets

เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม

ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด