It’s very easy to change the default homepage of the Django admin to show any other page you have already defined. For this example I’ll use the now famous “poll” application described in the Django documentation.
Assuming you already have setup the admin interface for the Poll model, your polls/admin.py file should look something like this:
from mysite.polls.models import Poll from django.contrib import admin admin.site.register(Poll)
and your urls.py file might be something like this:
from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)), )
Now, what if we wanted to show the list of Polls after the user logs in, instead of the default homepage showing the list of installed applications? This is how it’s done:
from mysite.polls.models import Poll from django.conf.urls.defaults import * from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^admin/$', admin.site.admin_view(admin.site._registry[Poll].changelist_view)), (r'^admin/', include(admin.site.urls)), )
Notice we’re adding an extra pattern to the urls.py file where we define the changelist_view as the view for the homepage. It is important to call admin.site.admin_view method so all the redirection rules work right.
That’s it!