تثبيت DRF وتهيئته
إضافة DRF وواجهة API القابلة للتصفح
تثبيت DRF وتهيئته درس مجاني في Django Academy على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Django Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Django Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
A REST API, Quickly
Django REST Framework, or DRF, layers a clean toolkit on top of Django so you can turn your models into a JSON API fast. 🚀
Install the Package
You add DRF the same way you add any Python library: with pip, then pin it in requirements so teammates get the same version.
pip install djangorestframeworkRegister the App
DRF only wakes up once you add rest_framework to your INSTALLED_APPS list in settings.py, right alongside your own apps.
INSTALLED_APPS = [
# ...
'rest_framework',
]Why INSTALLED_APPS Matters
Adding it to INSTALLED_APPS lets Django discover DRF's templates, static files, and management commands automatically.
The REST_FRAMEWORK Dict
You configure DRF through a single REST_FRAMEWORK dictionary in settings.py, keeping all of its options in one tidy place.
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [],
}Default Renderers
By default DRF can return both raw JSON and a friendly HTML view, thanks to its built-in renderers you rarely have to touch.
The Browsable API
One reason DRF feels magical is the browsable API: open an endpoint in your browser and you get a clickable, documented page. ✨
Wire Up the URLs
DRF ships login views for the browsable API; you include them in your urls.py so you can sign in while testing endpoints.
urlpatterns = [
path('api-auth/', include('rest_framework.urls')),
]Verify the Install
A quick way to confirm DRF is wired in is to open the Django shell and import it without errors before writing any code.
python manage.py shell
>>> import rest_frameworkKeep Settings Minimal
Start with an almost empty config. You only add keys to REST_FRAMEWORK when you genuinely need a behavior changed, not before.
You Are API-Ready
With DRF installed, registered, and its URLs included, your project is now ready to expose endpoints that speak JSON to any client.
Quick Check
Where does DRF need to be listed to activate?
Recap: DRF Set Up
You pip-installed DRF, added it to INSTALLED_APPS, included its auth URLs, and confirmed the import. Your API foundation is solid. 🎉
الأسئلة الشائعة
هل درس «تثبيت DRF وتهيئته» مجاني؟
نعم — نص درس «تثبيت DRF وتهيئته» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Django Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Django Academy 4 دروس في المجموع.
ماذا ستتعلم في «تثبيت DRF وتهيئته»؟
إضافة DRF وواجهة API القابلة للتصفح تتمرن على Django Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Django Academy؟
لا تُشترط خبرة سابقة. Django Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.
كم من الوقت يستغرق درس «تثبيت DRF وتهيئته»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Django Academy هذا؟
نعم. كل درس في Django Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تثبيت DRF وتهيئته
- Serializers: من النموذج إلى JSON
- APIView وFunction @api_view
- واجهة API القابلة للتصفح ورموز الحالة