القوالب والملفات الثابتة الخاصة بـ Blueprint
امنح كل Blueprint أصوله الخاصة.
القوالب والملفات الثابتة الخاصة بـ Blueprint درس مجاني في Flask Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Flask Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Flask Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Each Feature Owns Its Assets
A truly modular blueprint carries its own templates and static files. This keeps a feature self-contained and easy to move around.
Point to a Template Folder
When you create the blueprint, set template_folder so Flask also searches that folder when rendering this blueprint pages.
blog = Blueprint("blog", __name__,
template_folder="templates")Folders Are Relative
That template path is relative to the blueprint module thanks to __name__. Flask resolves it from where the blueprint file lives.
Templates Are Searched, Not Isolated
Flask merges every template folder into one search path. The blueprint folder is added to the global app templates, not fully walled off.
Avoid Template Name Clashes
Because folders merge, two blueprints with the same filename can collide. Namespace templates by nesting them in a per-blueprint subfolder.
render_template("blog/post.html")Add a Static Folder
A blueprint can ship its own CSS and images too. Set static_folder at creation to hold this feature private assets.
blog = Blueprint("blog", __name__,
static_folder="static")Link Blueprint Static Files
Reference those assets with url_for and the namespaced static endpoint, so each blueprint serves its own files cleanly.
url_for("blog.static", filename="blog.css")Set a Static URL Path
Give the assets a public route with static_url_path. This controls the URL browsers use to fetch the blueprint files.
Blueprint("blog", __name__,
static_url_path="/blog-static")App Static Still Exists
The main app keeps its own /static for shared assets. Blueprint statics live alongside it, each reached by its own endpoint.
A Tidy Blueprint Folder
The payoff is a clean package: routes, templates, and static files in one place. That folder is the whole feature, ready to reuse. 📦
blog/
routes.py
templates/blog/
static/blog.cssPortable by Design
Since assets travel with the code, you can copy a blueprint into another project and it still works with little extra setup. 🚀
Quick Check
How do you link a blueprint static file?
Recap
Set template_folder and static_folder on a blueprint so it owns its assets, namespace templates, and link statics via blog.static. 🎉
الأسئلة الشائعة
هل درس «القوالب والملفات الثابتة الخاصة بـ Blueprint» مجاني؟
نعم — نص درس «القوالب والملفات الثابتة الخاصة بـ Blueprint» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Flask Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Flask Academy 4 دروس في المجموع.
ماذا ستتعلم في «القوالب والملفات الثابتة الخاصة بـ Blueprint»؟
امنح كل Blueprint أصوله الخاصة. تتمرن على Flask Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Flask Academy؟
لا تُشترط خبرة سابقة. Flask Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «القوالب والملفات الثابتة الخاصة بـ Blueprint»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Flask Academy هذا؟
نعم. كل درس في Flask Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- لماذا تتفوق Blueprints على ملف واحد ضخم
- إنشاء Blueprint وتسجيله
- بادئات URL وBlueprint url_for
- القوالب والملفات الثابتة الخاصة بـ Blueprint