0Pricing
Django Academy · درس

MTV: Models وTemplates وViews

كيف يقسّم Django المسؤوليات، وكيف يقابل MTV نمط MVC

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

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

Three Clear Jobs

Django splits an app into three roles so code stays tidy. This pattern is called MTV: Models, Templates, and Views, each with one clear job.

Models Hold Data

A Model describes your data, like a Post or a User. Django turns that Python class into a database table you can query without writing SQL.

class Post(models.Model):
    title = models.CharField(max_length=120)
    body = models.TextField()

Templates Show Data

A Template is an HTML file with placeholders. It decides how data looks on the page, keeping design separate from your Python logic.

<h1>{{ post.title }}</h1>
<p>{{ post.body }}</p>

Views Connect Both

A View is the brain: it takes a request, grabs data from models, and hands it to a template to render. It glues the pieces together.

def post_list(request):
    posts = Post.objects.all()
    return render(request, "list.html", {"posts": posts})

The Flow in One Breath

Request comes in, a view fetches model data, then a template renders the result. That round trip is the heartbeat of every Django page.

MTV Meets MVC

You may know MVC from elsewhere. MTV is the same idea renamed: Model is Model, Template is the View, and Django's View plays the Controller.

Why the Names Differ

Django calls the page layer a Template because Django itself handles the controlling. The framework is the controller, so the word would just confuse you.

Separation of Concerns

Keeping data, logic, and design apart is called separation of concerns. Change a template's look without touching models, and your code stays calm. 🧩

Where Each Lives

Models sit in models.py, views in views.py, and templates in a templates folder. Knowing where things go is half of working confidently in Django.

URLs Point to Views

One missing link ties it together: a URL pattern maps a web address to the right view, so Django knows which code to run for each page.

urlpatterns = [
    path("posts/", post_list),
]

Why MTV Helps You

With clear roles, teams work in parallel and bugs are easier to find. You always know where a change belongs, even months later. 🙌

Quick Check

Which layer does the heavy lifting?

Recap

You now see Django's MTV: models hold data, templates show it, and views connect both. It is just MVC renamed, keeping concerns cleanly separate. ✨

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

هل درس «MTV: Models وTemplates وViews» مجاني؟

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

ماذا ستتعلم في «MTV: Models وTemplates وViews»؟

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

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

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

كم من الوقت يستغرق درس «MTV: Models وTemplates وViews»؟

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

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

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

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

  1. ما هو Django وما المشكلات التي يحلّها
  2. MTV: Models وTemplates وViews
  3. كل شيء مضمَّن: ORM وAdmin وAuth
  4. هل Django مناسب لمشروعك؟
← العودة إلى Django Academy