› Forums › Web Development › HarvardX: CS50W – CS50’s Web Programming with Python and JavaScript › CS50W – Lecture 3 – Django › Why admin.site.urls Works in Django Without Creating Your Own Views
- This topic is empty.
-
AuthorPosts
-
April 28, 2026 at 11:08 am #6461
If you’re learning Django, one confusing line often appears in
urls.py:path("admin/", admin.site.urls)You may wonder:
Where is the view function?
Why does this route work even though I didn’t createviews.pyfor admin?Let’s break it down clearly.
Django Already Includes a Ready-Made Admin App
Unlike routes you create manually, Django ships with a complete built-in administration system.
When you write:
from django.contrib import adminyou import Django’s admin package.
Inside it, Django already provides:
- Login page
- Logout page
- Password change page
- User management
- Groups and permissions
- Model data management
- Add / edit / delete records
So the admin system is already built before your project starts.
What
admin.site.urlsMeansThis part:
admin.site.urlsis a collection of URL routes that Django has prepared for you.
So when you write:
path("admin/", admin.site.urls)you are telling Django:
Send all
/admin/traffic to the built-in admin application.
Why No Custom
views.pyIs NeededNormally you create routes like:
path("about/", views.about)That needs your own view function:
def about(request): return HttpResponse("About page")But admin is different because Django already contains the views internally.
You are reusing Django’s built-in code.
Real-World Analogy
Think of your website as a building.
- Your custom pages = rooms you design yourself
- Django Admin = a fully furnished control room already installed
You only connect the door:
path("admin/", ...)and it starts working.
Why This Is Powerful
Instead of coding an admin dashboard from scratch, Django gives one instantly.
That saves huge development time.
Once you create models such as:
class Article(models.Model): title = models.CharField(max_length=100)you can register them and manage records through
/admin/.
Comparison with WordPress
WordPress also gives a ready-made admin area:
/wp-admin/Difference:
- WordPress focuses on CMS management
- Django Admin focuses on database-backed app management for developers
Key Learning Point
Frameworks like Django often include reusable systems.
So not every page must be coded manually.
Some routes connect to features already provided by the framework.
Short Summary
path("admin/", admin.site.urls)means:
Use Django’s built-in admin app for all
/admin/pages.No custom view required because Django already built it for you.
Beginner Tip
When learning frameworks, always ask:
- Is this route custom code?
- Or is it a built-in reusable feature?
That mindset helps you understand professional development faster.
-
AuthorPosts
- You must be logged in to reply to this topic.
