موارد REST المثبّتة على Blueprint
ثبّت Api على Blueprint بطريقة نظيفة.
موارد REST المثبّتة على Blueprint درس مجاني في Flask Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Flask Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Flask Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
APIs Grow, So Modularize
As your API expands, keep it tidy by mounting resources on a blueprint instead of the global app. 🧱
Why a Blueprint Here
A blueprint groups related routes and can carry a URL prefix, keeping every API endpoint under one namespace.
Create the Blueprint
Define a Blueprint for your API. Give it a name and the import name so Flask can locate it.
from flask import Blueprint
api_bp = Blueprint("api", __name__)Bind the Api to It
Pass the blueprint to Api instead of the app. Now resources attach to the blueprint, not the whole app.
from flask_restful import Api
api = Api(api_bp)Add Resources as Usual
Mount resources with add_resource exactly like before. Paths here are relative to the blueprint.
api.add_resource(TaskList, "/tasks")Register with a Prefix
When you register the blueprint, add a url_prefix so every resource sits under a shared base like /api.
app.register_blueprint(api_bp, url_prefix="/api")The Full URL
A resource at /tasks on a blueprint prefixed with /api answers at /api/tasks. Prefix plus path combine.
Keep It in Its Own Module
Put the blueprint and its resources in a separate file, then import and register it where you build the app.
from .api import api_bp
app.register_blueprint(api_bp)Pairs With the App Factory
Inside create_app, register the API blueprint alongside others. The factory becomes your single wiring point.
def create_app():
app = Flask(__name__)
app.register_blueprint(api_bp, url_prefix="/api")
return appVersion Your API
A prefix makes versioning easy: mount the same blueprint under /api/v1 and ship breaking changes safely.
app.register_blueprint(api_bp, url_prefix="/api/v1")Multiple API Blueprints
Split large APIs into several blueprints, each with its own Api and prefix, for clear ownership of each area.
Quick Check
Your blueprint is registered with url_prefix=/api and a resource sits at /tasks. What is the final URL?
Recap: Modular REST
You bound an Api to a blueprint, mounted resources, and added a prefix for clean, versionable APIs. Organized! 🎉
تعلم Python مع معلم ذكاء اصطناعي — مجانًا
اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.
- الدورات
- 30
- الدروس
- 120
الأسئلة الشائعة
هل درس «موارد REST المثبّتة على Blueprint» مجاني؟
نعم — نص درس «موارد REST المثبّتة على Blueprint» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Flask Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Flask Academy 4 دروس في المجموع.
ماذا ستتعلم في «موارد REST المثبّتة على Blueprint»؟
ثبّت Api على Blueprint بطريقة نظيفة. تتمرن على Flask Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Flask Academy؟
لا تُشترط خبرة سابقة. Flask Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «موارد REST المثبّتة على Blueprint»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Flask Academy هذا؟
نعم. كل درس في Flask Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- فئات الموارد وكائن Api
- ربط أساليب HTTP بمعالجات الفئات
- تحليل المدخلات والتحقق منها باستخدام reqparse
- موارد REST المثبّتة على Blueprint