0Pricing
Django Academy · درس

التعامل مع طرائق get وpost

توجيه أفعال HTTP إلى أساليب الفئات

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

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

Verbs Become Methods

In a CBV, each HTTP verb maps to a method. A GET request runs your get method; a POST request runs your post method.

Subclass the Base View

For full control over verbs, subclass the base View class. You then define exactly the methods you want to support.

class ContactView(View):
    pass

Define a get Method

Add a get method to show the page, for example an empty contact form. It takes self and request and returns a response.

def get(self, request):
    return render(request, "contact.html")

Define a post Method

Add a post method to handle submitted data. Django routes the POST request here automatically.

def post(self, request):
    name = request.POST.get("name")
    return redirect("thanks")

No More method Checks

You no longer write if request.method == "POST". Django dispatches to the right method based on the verb for you.

dispatch Routes the Request

Behind the scenes, a method called dispatch inspects the verb and calls the matching method. You rarely touch it directly.

Unsupported Verbs Get 405

If a request uses a verb you did not define, Django returns 405 Method Not Allowed automatically. Safe by default.

The Classic GET-then-POST Flow

The usual pattern: get shows a form, the user submits, and post processes it. Two methods, one clean class.

Redirect After POST

After a successful post, return a redirect instead of rendering. This stops duplicate submissions on refresh.

Share State via self

Both methods live in the same class, so you can store shared values on self or call helper methods you define.

Wire It With as_view

Route the class the usual way with as_view(). Django builds the dispatcher and your get and post just work.

path("contact/", ContactView.as_view())

Quick Check

What happens on a POST to a CBV that only defines get?

Recap: get and post

You saw how CBVs map verbs to methods: get shows, post handles, dispatch routes, and undefined verbs return 405. No manual method checks. 🚦

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

هل درس «التعامل مع طرائق get وpost» مجاني؟

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

ماذا ستتعلم في «التعامل مع طرائق get وpost»؟

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

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

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

كم من الوقت يستغرق درس «التعامل مع طرائق get وpost»؟

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

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

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

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

  1. من Views الدالية إلى فئات View
  2. ‏TemplateView وget_context_data
  3. التعامل مع طرائق get وpost
  4. Mixins و as_view()
← العودة إلى Django Academy