# Django REST Framework (Django) > Serializer, ViewSet, router, การยืนยันตัวตน, สิทธิ์, การแบ่งหน้า, การกรอง, throttling, การจัดเวอร์ชัน - 30 คำถามสัมภาษณ์ - Mid-Level - [คำถามสัมภาษณ์: Django](https://sharpskill.dev/th/technologies/django/interview-questions.md) ## 1. Django REST Framework (DRF) คืออะไร? **คำตอบ** Django REST Framework เป็น toolkit ที่ทรงพลังและยืดหยุ่นสำหรับการสร้าง Web API ด้วย Django โดยมีฟีเจอร์ต่าง ๆ เช่น การ serialize, การยืนยันตัวตน, สิทธิ์, การแบ่งหน้า และเอกสารอัตโนมัติ ด้วยอินเทอร์เฟซที่เรียกดูได้และคอมโพเนนต์ที่นำกลับมาใช้ใหม่ได้ DRF จึงกลายเป็นมาตรฐานโดยพฤตินัยสำหรับการสร้าง RESTful API ใน Python ด้วย Django ## 2. บทบาทหลักของ Serializer ใน DRF คืออะไร? **คำตอบ** Serializer ใน DRF จะแปลงอ็อบเจ็กต์ที่ซับซ้อน เช่น instance ของ model ใน Django ให้เป็นชนิดข้อมูล Python ดั้งเดิม ซึ่งจากนั้นสามารถ render ออกเป็น JSON หรือ XML ได้อย่างง่ายดาย นอกจากนี้ยังจัดการการตรวจสอบความถูกต้องของข้อมูลขาเข้าและการ deserialize เพื่อแปลงข้อมูล JSON ให้เป็นอ็อบเจ็กต์ Python อีกด้วย Serializer เป็นหัวใจสำคัญของ DRF และช่วยให้สามารถกำหนดการแสดงข้อมูลของ API ได้ ## 3. ความแตกต่างระหว่าง Serializer และ ModelSerializer คืออะไร? **คำตอบ** ModelSerializer เป็นคลาสย่อยของ Serializer ที่สร้างฟิลด์โดยอัตโนมัติตาม model ของ Django ที่เชื่อมโยงอยู่ มันจะสร้าง validator ให้โดยอัตโนมัติ ใช้งานเมธอด create() และ update() แบบค่าเริ่มต้น และลดโค้ด boilerplate ลงอย่างมาก ส่วน Serializer ต้องกำหนดแต่ละฟิลด์รวมถึงเมธอดสร้าง/อัปเดตด้วยตนเอง ซึ่งให้การควบคุมมากกว่าแต่ต้องเขียนโค้ดมากกว่า ## มีอีก 27 คำถาม - จะกำหนดว่าจะรวมฟิลด์ใดบ้างใน ModelSerializer ได้อย่างไร? - จะเพิ่มการตรวจสอบความถูกต้องแบบกำหนดเองให้กับ field ที่เฉพาะเจาะจงใน Serializer ได้อย่างไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Django อื่นๆ - [พื้นฐาน Python](https://sharpskill.dev/th/technologies/django/interview-questions/python-basics.md): 25 คำถาม, Junior - [Python เชิงวัตถุ](https://sharpskill.dev/th/technologies/django/interview-questions/python-oop.md): 20 คำถาม, Junior - [พื้นฐาน Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-fundamentals.md): 20 คำถาม, Junior - [Django Models - พื้นฐาน](https://sharpskill.dev/th/technologies/django/interview-questions/django-models-basics.md): 22 คำถาม, Junior - [Django Views](https://sharpskill.dev/th/technologies/django/interview-questions/django-views.md): 20 คำถาม, Junior - [เทมเพลต Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-templates.md): 18 คำถาม, Junior - [ฟอร์ม Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-forms.md): 22 คำถาม, Mid-Level - [QuerySets ขั้นสูง](https://sharpskill.dev/th/technologies/django/interview-questions/django-querysets.md): 25 คำถาม, Mid-Level - [การยืนยันตัวตนใน Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-authentication.md): 22 คำถาม, Mid-Level - [Django Middleware](https://sharpskill.dev/th/technologies/django/interview-questions/django-middleware.md): 18 คำถาม, Mid-Level - [Django Admin](https://sharpskill.dev/th/technologies/django/interview-questions/django-admin.md): 20 คำถาม, Mid-Level - [Django Signals](https://sharpskill.dev/th/technologies/django/interview-questions/django-signals.md): 18 คำถาม, Mid-Level - [การอัปโหลดไฟล์](https://sharpskill.dev/th/technologies/django/interview-questions/django-file-upload.md): 20 คำถาม, Mid-Level - [การแคชใน Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-caching.md): 20 คำถาม, Mid-Level - [Django Sessions](https://sharpskill.dev/th/technologies/django/interview-questions/django-sessions.md): 18 คำถาม, Mid-Level - [อีเมลใน Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-email.md): 18 คำถาม, Mid-Level - [การทดสอบ Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-testing.md): 22 คำถาม, Mid-Level - [ความปลอดภัยของ Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-security.md): 22 คำถาม, Mid-Level - [การ Deploy Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-deployment.md): 24 คำถาม, Mid-Level - [Django ORM ขั้นสูง](https://sharpskill.dev/th/technologies/django/interview-questions/django-orm-advanced.md): 28 คำถาม, Senior - [ประสิทธิภาพของ Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-performance.md): 24 คำถาม, Senior - [Django & Celery](https://sharpskill.dev/th/technologies/django/interview-questions/django-celery.md): 22 คำถาม, Senior - [Django Channels](https://sharpskill.dev/th/technologies/django/interview-questions/django-channels.md): 24 คำถาม, Senior - [Django & GraphQL](https://sharpskill.dev/th/technologies/django/interview-questions/django-graphql.md): 24 คำถาม, Senior - [Django & Docker](https://sharpskill.dev/th/technologies/django/interview-questions/django-docker.md): 20 คำถาม, Senior - [Django ในระบบนิเวศ Microservices](https://sharpskill.dev/th/technologies/django/interview-questions/django-microservices.md): 24 คำถาม, Senior - [คำสั่ง Django แบบกำหนดเอง](https://sharpskill.dev/th/technologies/django/interview-questions/django-custom-commands.md): 18 คำถาม, Senior - [การทำให้รองรับหลายภาษาใน Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-internationalization.md): 20 คำถาม, Senior - [Design Patterns ใน Django](https://sharpskill.dev/th/technologies/django/interview-questions/django-design-patterns.md): 24 คำถาม, Senior - [Django Async และ ASGI](https://sharpskill.dev/th/technologies/django/interview-questions/django-async-asgi.md): 26 คำถาม, Senior - [Settings และการตั้งค่า Production](https://sharpskill.dev/th/technologies/django/interview-questions/django-settings-configuration.md): 22 คำถาม, Senior - [Observability และ Monitoring](https://sharpskill.dev/th/technologies/django/interview-questions/django-observability.md): 24 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/django/interview-questions/django-rest-framework