عرض النماذج في القوالب
اعرض الحقول والتسميات والأخطاء بأمان
عرض النماذج في القوالب درس مجاني في Django Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Django Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Django Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Pass the Form In
Send your form to the template through the context, just like any other variable, so it can be rendered.
return render(request, "contact.html",
{"form": form})Render Everything at Once
Printing {{ form }} outputs every field with its label, widget, and errors. It is the fastest way to get a working form.
<form method="post">
{{ form }}
</form>Pick a Layout Helper
Use as_p, as_div, or as_table to wrap each field in a tidy structure without writing the markup yourself.
{{ form.as_p }}Render One Field
Access a single field by name to control its placement. {{ form.name }} renders just that widget.
{{ form.email }}Show the Label
Pair a field with label_tag to output a proper label element linked to the input for accessibility.
{{ form.email.label_tag }}
{{ form.email }}Display Field Errors
Each bound field exposes its own errors, so you can place validation messages right beside the matching input.
{{ form.email.errors }}Non-Field Errors
Errors raised in form-wide clean() are non_field_errors. Render them at the top of the form, not on any single field.
{{ form.non_field_errors }}Loop Over Fields
Iterate the form with a for loop to render every field the same way while keeping full control of the wrapper markup.
{% for field in form %}
{{ field.label_tag }} {{ field }}
{% endfor %}Show help_text
Inside the loop, output field.help_text to guide users with the hint you defined on that field.
{{ field.help_text }}Add the Submit Button
Django renders inputs but not the submit button or the form tag, so you always add those yourself.
<button type="submit">Send</button>Auto-Escaping Keeps You Safe
The template engine escapes rendered values by default, so user input cannot inject HTML and cause XSS.
Quick Check
How do forms render in templates?
Recap
Pass the form in, render it with as_p or field by field, and show errors. You always add the form tag and button. ✅
الأسئلة الشائعة
هل درس «عرض النماذج في القوالب» مجاني؟
نعم — نص درس «عرض النماذج في القوالب» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Django Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Django Academy 4 دروس في المجموع.
ماذا ستتعلم في «عرض النماذج في القوالب»؟
اعرض الحقول والتسميات والأخطاء بأمان تتمرن على Django Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Django Academy؟
لا تُشترط خبرة سابقة. Django Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «عرض النماذج في القوالب»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Django Academy هذا؟
نعم. كل درس في Django Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تعريف forms.Form
- is_valid وcleaned_data
- عرض النماذج في القوالب
- حماية CSRF وتدفّق POST