تمرير البيانات إلى قالب
أرسل متغيرات Python إلى الصفحة المُصيّرة.
تمرير البيانات إلى قالب درس مجاني في Flask Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Flask Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Flask Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Pages That Change
Static HTML is fine, but real pages show different data per user. You make pages dynamic by passing data from your view into the template.
Keyword Arguments
Add keyword arguments to render_template. Each name you pass becomes a variable you can use inside the HTML file.
return render_template('hi.html', name='Ada')Reading a Variable
Inside the template, print a value with double curly braces. Flask swaps the expression for its result when the page renders.
<h1>Hello, {{ name }}!</h1>The Expression Delimiter
Those {{ }} markers mean output this value here. Anything inside is evaluated and its result is written into the page.
Passing Many Values
You can pass as many keyword arguments as you need. Each one is independent and available throughout the template.
return render_template('p.html', name='Ada', age=36)Passing Lists
Values are not limited to text. You can hand a template a list or any Python object and work with it in the markup.
return render_template('t.html', items=['a','b','c'])Accessing Object Attributes
Use a dot to reach attributes, just like in Python. Templates read object properties the same intuitive way you do in code.
<p>{{ user.email }}</p>Dictionary Lookups
For a dictionary, use either the dot or bracket form. Jinja2 tries attribute access first, then falls back to a key lookup.
{{ data.title }} or {{ data['title'] }}Missing Values Are Safe
If a variable is undefined, Jinja2 renders nothing instead of crashing. That keeps a small typo from breaking the whole page.
Applying Filters
Transform a value on the fly with a filter, written after a pipe. Filters format text without cluttering your Python view.
<h1>{{ name|upper }}</h1>Keep Logic in the View
Do heavy work in Python and pass ready values in. Templates should display data, not compute it, which keeps pages simple.
Quick Check
How do you output a variable named title inside a Jinja2 template?
Recap
You now pass data through keyword arguments and print it with double curly braces, even reaching attributes and applying filters. Great progress! 🚀
الأسئلة الشائعة
هل درس «تمرير البيانات إلى قالب» مجاني؟
نعم — نص درس «تمرير البيانات إلى قالب» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Flask Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Flask Academy 4 دروس في المجموع.
ماذا ستتعلم في «تمرير البيانات إلى قالب»؟
أرسل متغيرات Python إلى الصفحة المُصيّرة. تتمرن على Flask Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Flask Academy؟
لا تُشترط خبرة سابقة. Flask Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «تمرير البيانات إلى قالب»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Flask Academy هذا؟
نعم. كل درس في Flask Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- render_template ومجلد templates
- تمرير البيانات إلى قالب
- الحلقات والشروط في Jinja2
- التحويل التلقائي ومرشّح safe