Django Apps की व्याख्या
In this page:
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 हो सकते हैं।
उदाहरण: 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.
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.
# 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.
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.
- एक Django project को एक Django app के साथ confuse करना — एक project पूरी website है, एक app इसके अंदर एक reusable feature है।
- किसी website की हर feature को अलग concerns में apps में बांटने के बजाय एक giant app में भरना।
- यह भूल जाना कि एक 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 रखता है।
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: