تحليل الأداء باستخدام Debug Toolbar
قياس عدد الاستعلامات ووقتها
تحليل الأداء باستخدام Debug Toolbar درس مجاني في Django Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Django Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Django Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Measure, Do Not Guess
The Django Debug Toolbar shows exactly how many queries a page runs, so you optimize with facts instead of hunches. 🔍
Install It
You add it with pip, just like any package. It is a development tool, so it never ships to production.
pip install django-debug-toolbarRegister the App
Add it to INSTALLED_APPS so Django loads its panels and knows the toolbar exists.
INSTALLED_APPS += ['debug_toolbar']Add the Middleware
Its middleware injects the panel into HTML responses, so it sits near the top of your middleware list.
MIDDLEWARE += [
'debug_toolbar.middleware.DebugToolbarMiddleware']Allow Your IP
The toolbar only appears for IPs in INTERNAL_IPS, which keeps it visible to you but hidden from real visitors.
INTERNAL_IPS = ['127.0.0.1']The SQL Panel
The star panel is SQL. It lists every query a page ran, with its timing, right beside the rendered output.
Spot the Query Count
A surprisingly high query count is the classic fingerprint of N+1. The toolbar makes that number impossible to miss.
Find Duplicates
It even flags duplicate queries, the near-identical ones a loop fires over and over, pointing straight at the problem.
Confirm Your Fix
After adding select_related or prefetch_related, reload and watch the count drop. That is your proof the fix worked.
Read the Timings
Slow pages are not always about count. The toolbar shows time per query, so you can chase the truly expensive ones.
Keep It Dev-Only
Wrap toolbar settings behind your DEBUG flag. It can leak internals and slow pages, so production must never see it.
Quick Check
One last check on profiling habits.
Recap
The Debug Toolbar counts and times queries so you can spot N+1 and confirm fixes. Install it, allow your IP, and keep it dev-only. ✅
الأسئلة الشائعة
هل درس «تحليل الأداء باستخدام Debug Toolbar» مجاني؟
نعم — نص درس «تحليل الأداء باستخدام Debug Toolbar» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Django Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Django Academy 4 دروس في المجموع.
ماذا ستتعلم في «تحليل الأداء باستخدام Debug Toolbar»؟
قياس عدد الاستعلامات ووقتها تتمرن على Django Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Django Academy؟
لا تُشترط خبرة سابقة. Django Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «تحليل الأداء باستخدام Debug Toolbar»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Django Academy هذا؟
نعم. كل درس في Django Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- اكتشاف مشكلة N+1
- select_related للمفاتيح الأجنبية
- prefetch_related لعلاقات M2M
- تحليل الأداء باستخدام Debug Toolbar