0Pricing
Django Academy · درس

رموز الحالة والفئات الفرعية لـ HttpResponse

استخدم JsonResponse وعمليات إعادة التوجيه ومساعدات 404

رموز الحالة والفئات الفرعية لـ HttpResponse درس مجاني في Django Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Django Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Django Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

What Status Codes Mean

Every response carries a status code. The number tells the browser if things went well, moved, or broke. 🚦

The Friendly 2xx Codes

Codes in the 2xx range mean success. 200 is the everyday OK, and 201 signals that something new was created.

Redirects in the 3xx Range

A 3xx code tells the browser to go elsewhere. 301 is a permanent move, while 302 is a temporary redirect.

Client Errors: 4xx

The 4xx codes blame the request. 404 means not found, 403 means forbidden, and 400 means a bad request.

JsonResponse for APIs

Use JsonResponse to send data as JSON. Pass a dict and Django sets the right content type for you.

return JsonResponse({"name": "Ada"})

Redirecting with redirect

The redirect shortcut returns a 302 to another URL or view name, so users land exactly where you want them.

return redirect('home')

HttpResponseRedirect

Behind redirect sits HttpResponseRedirect. Give it a URL and it builds the 302 response for you directly.

return HttpResponseRedirect('/login/')

Permanent Redirects

For a permanent move, use HttpResponsePermanentRedirect, which sends a 301 so browsers remember the new address.

Raising a 404

Raise Http404 when a record is missing. Django catches it and shows your not-found page with a 404 code.

raise Http404("No such post")

get_object_or_404

The get_object_or_404 helper fetches a row or raises Http404 automatically, saving you a manual check.

post = get_object_or_404(Post, pk=3)

Pick the Right Subclass

Choosing the right subclass sets a correct status with no manual numbers, keeping your views clear and honest.

Quick Check

Which response sends JSON with the correct content type?

Recap: Speak in Codes

Status codes and HttpResponse subclasses like JsonResponse, redirect, and Http404 let your views answer clearly. 🚀

الأسئلة الشائعة

هل درس «رموز الحالة والفئات الفرعية لـ HttpResponse» مجاني؟

نعم — نص درس «رموز الحالة والفئات الفرعية لـ HttpResponse» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Django Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Django Academy 4 دروس في المجموع.

ماذا ستتعلم في «رموز الحالة والفئات الفرعية لـ HttpResponse»؟

استخدم JsonResponse وعمليات إعادة التوجيه ومساعدات 404 تتمرن على Django Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Django Academy؟

لا تُشترط خبرة سابقة. Django Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «رموز الحالة والفئات الفرعية لـ HttpResponse»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Django Academy هذا؟

نعم. كل درس في Django Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. كيف يصل الطلب إلى View الخاصة بك
  2. كائن HttpRequest
  3. إرجاع HttpResponse
  4. رموز الحالة والفئات الفرعية لـ HttpResponse
← العودة إلى Django Academy