Django Admin का परिचय
Admin App आपको क्या देता है
Django django.contrib.admin के साथ already INSTALLED_APPS में listed और already urls.py में routed आता है। यह आपके models पढ़ता है और उनके लिए list, add, edit, और delete pages अपने आप बनाता है -- आपसे कोई HTML नहीं चाहिए।
/admin/ पर जाकर देख सकते हैं।उदाहरण: What the Admin App Gives You
This is the line already present in a new project's urls.py that wires the admin app to the /admin/ path.
urlpatterns = [
path('admin/', admin.site.urls),
]
{# 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. #}
Login करना
Admin एक login screen से protected है। सिर्फ एक user जो staff मार्क किया गया हो (और आमतौर पर एक superuser) sign in कर सकता है, इसलिए आपको admin उपयोग करने से पहले उन permissions वाला एक account चाहिए।
उदाहरण: Logging In
Running this command creates the account you'll use to log in to /admin/.
python manage.py createsuperuser
⚠️ Run this in your own terminal or Node.js environment.
Models Default से क्यों नहीं दिखते
Django guess नहीं करता कि आप कौन से models admin में managed करना चाहते हैं। हर model को इसके app के admin.py में register किया जाना चाहिए, नहीं तो admin site इसे simply list नहीं करेगी।
admin.py registration नहीं है वह dashboard में invisible है भले ही वह database में मौजूद हो।उदाहरण: Why Models Don't Appear by Default
Adding this to an app's admin.py makes the Book model show up in the admin dashboard.
from django.contrib import admin
from .models import Book
admin.site.register(Book)
{# 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. #}
- यह मान लेना कि admin site website के public-facing part होने के लिए है, एक private management tool होने के बजाय।
- यह भूल जाना कि admin सिर्फ वे models दिखाता है जिन्हें आपने explicitly register किया है, फिर यह सोचना कि एक model 'क्यों नहीं दिखता'।
- Default
/admin/URL और default superuser credentials को एक असली production deployment पर exposed छोड़ देना।
django.contrib.adminएक built-in app है जो आपके models के लिए अपने आप एक पूरा CRUD interface generate करता है।- यह default रूप से एक नए project के
INSTALLED_APPSमें enabled है औरurls.pyमें wired up है। - आपको अब भी हर model को admin में दिखने से पहले register करना होगा।
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: