← Back to Django Course | Chapter 2: Apps, URLs & Views | Lesson 1 of 10

Django Apps की व्याख्या

एक Django app एक बड़े toy room (आपका project) के अंदर एक toy box जैसा है — हर box सिर्फ एक job के toys रखता है, जैसे एक blog box या एक shop box।

Project vs App

एक Django *project* आपकी पूरी website के लिए top-level configuration है — settings, root URLs, WSGI/ASGI entry points। एक *app* एक छोटा Python package है जो एक piece of functionality implement करता है, जैसे एक blog या एक shopping cart।

एक project में (और usually होता भी है) कई apps हो सकते हैं।

Note: एक अच्छा rule of thumb: अगर एक feature एक पूरी तरह अलग website में reuse हो सकता है, तो इसे probably अपना एक app चाहिए।

उदाहरण: Project vs App

startproject creates the project (the whole site's config); startapp creates blog/ as one self-contained piece of functionality inside it — that's the literal command-level difference between a project and an app.

bash
django-admin startproject mysite
cd mysite
python manage.py startapp blog

⚠️ Run this in your own terminal or Node.js environment.

एक App के अंदर क्या रहता है

हर Django app एक normal Python package है (एक __init__.py वाला folder) जिसमें conventionally database tables के लिए models.py, request-handling logic के लिए views.py, इसके अपने routes के लिए urls.py, और admin registration के लिए एक admin.py होता है।

उदाहरण: What Lives Inside an App

Every app groups its own models.py (data) and views.py (request-handling) together — this Post model and post_list view both live inside the same blog/ app folder.

markup
# blog/models.py
from django.db import models

class Post(models.Model):
    title = models.CharField(max_length=200)

# blog/views.py
from django.shortcuts import render
from .models import Post

def post_list(request):
    return render(request, 'blog/post_list.html', {'posts': Post.objects.all()})
{# Django-only code -- models.py/views.py/urls.py/settings.py snippets, or template markup using Django template tags/variables -- can't run standalone via Judge0 or the browser preview, since it needs a real Django project. Only this course's pure-Python examples (example_lang == 'python', no Django imports) are actually runnable, so those still get the button below. #}

Apps Reusable हैं

क्योंकि एक app सिर्फ अपने models, views, और templates के बारे में जानता है, वही app minimal changes के साथ एक अलग Django project में drop किया जा सकता है।

यही कारण है कि कई third-party Django packages (django-allauth, django-rest-framework) installable apps के रूप में ship होती हैं।

उदाहरण: Apps Are Reusable

Because an app only knows about its own models, views, and templates, the same app can be dropped into a different Django project with minimal changes. This is why many third-party Django packages (django-allauth, django-rest-framework) ship as installable apps.

bash
pip install django-allauth
# django-allauth is itself a Django app you add to INSTALLED_APPS

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक Django project को एक Django app के साथ confuse करना — एक project पूरी website है, एक app इसके अंदर एक reusable feature है।
  2. किसी website की हर feature को अलग concerns में apps में बांटने के बजाय एक giant app में भरना।
  3. यह भूल जाना कि एक app सिर्फ एक plain Python package है जब तक यह INSTALLED_APPS में register न हो।
चैप्टर सारांश
  • एक Django project पूरी website configuration है; एक app इसके अंदर एक self-contained feature module है।
  • Apps सिर्फ files के एक conventional set वाले Python packages हैं (models.py, views.py, urls.py, आदि)।
  • एक site को apps (blog, shop, accounts) में split करना code को organized और projects के बीच reusable रखता है।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.