← Back to Django Course | Chapter 8: Django Admin | Lesson 1 of 8

Django Admin का परिचय

Django का admin एक ready-made dashboard है जहां आप अपने database records को इसके लिए खुद कोई web pages लिखे बिना add, edit, और delete कर सकते हैं।

Admin App आपको क्या देता है

Django django.contrib.admin के साथ already INSTALLED_APPS में listed और already urls.py में routed आता है। यह आपके models पढ़ता है और उनके लिए list, add, edit, और delete pages अपने आप बनाता है -- आपसे कोई HTML नहीं चाहिए।

Note: आप इसे किसी भी fresh Django project में superuser बनाने के बाद /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.

markup
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/.

bash
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 नहीं करेगी।

Warning: एक model जिसका कोई 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.

markup
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. #}
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. यह मान लेना कि admin site website के public-facing part होने के लिए है, एक private management tool होने के बजाय।
  2. यह भूल जाना कि admin सिर्फ वे models दिखाता है जिन्हें आपने explicitly register किया है, फिर यह सोचना कि एक model 'क्यों नहीं दिखता'।
  3. 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 करना होगा।

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.