0Pricing
Flask Academy · درس

تسجيل Blueprints في المصنع

اربط جميع Blueprints أثناء تجميع التطبيق.

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

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

The Final Assembly

With the app built and extensions bound, the last factory job is wiring up your routes. You do that by registering blueprints. 🧩

A Quick Blueprint Recall

A blueprint groups related routes into a reusable module. The factory is exactly where you attach those groups to the app.

from flask import Blueprint
main = Blueprint("main", __name__)

Register Inside create_app

Import each blueprint and call app.register_blueprint on the fresh app, all within the factory body.

def create_app():
    app = Flask(__name__)
    from .main import main
    app.register_blueprint(main)
    return app

Import Inside the Function

Notice the blueprint import sits inside create_app. This deferred import is the trick that breaks circular import chains.

Add a URL Prefix

Give a blueprint its own path namespace with url_prefix at registration time, keeping related routes neatly grouped.

app.register_blueprint(api, url_prefix="/api")

Register Several

Real apps have many blueprints. Register each one in the factory, and each contributes its own slice of routes to the app.

app.register_blueprint(auth)
app.register_blueprint(blog)
app.register_blueprint(api, url_prefix="/api")

Order Is Predictable

Because registration happens in one place, the setup order is obvious and easy to read: config, extensions, then blueprints.

Everything in One View

The factory reads like a recipe: make the app, load config, init extensions, register blueprints, return. One glance shows the whole wiring. 👀

Endpoints Get Namespaced

Blueprint endpoints are prefixed by the blueprint name, so url_for uses blueprint.view to link across modules without clashes.

url_for("main.home")

Fresh Wiring Every Time

Each call to create_app registers blueprints onto a brand new app, so tests and prod never share route state.

The Complete Pattern

Config, extensions via init_app, and blueprints via register_blueprint, all inside the factory. That is the full application factory pattern.

Quick Check

Where should blueprints be registered in the factory pattern?

Recap

You finished the pattern: register blueprints inside create_app with deferred imports and optional prefixes. Config, extensions, blueprints, return. 🏁

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

هل درس «تسجيل Blueprints في المصنع» مجاني؟

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

ماذا ستتعلم في «تسجيل Blueprints في المصنع»؟

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

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

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

كم من الوقت يستغرق درس «تسجيل Blueprints في المصنع»؟

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

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

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

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

  1. مشكلات كائن app العام
  2. كتابة دالة create_app
  3. تهيئة الامتدادات باستخدام init_app
  4. تسجيل Blueprints في المصنع
← العودة إلى Flask Academy