Previous Page Next Page

Overriding the Built-in Admin Views in the URLconf File

Another option for customizing the admin interface is to simply override the admin URL patterns with your own. You can override patterns that normally link to admin views by adding your own patterns before including the django.contrib.admin.urls URLconf file.

Using this method, you can have admin URLs access your own custom views. For example, if you wanted to override the admin index view with a custom view function, you could add the following URL pattern:

(r'^admin/$', 'mySite.CustomViews.views.site_index'),

Did you Know?

You can actually do some processing in your view function and then call the admin view function to render the view. However, you must know exactly what you are doing.


Try It Yourself: Override the Admin Logout URL

In this section, you will override the admin/logout URL to link to the iFriends.Home.views.logout_user view function. Follow these steps to override the URL:

1.
Open the iFriends/urls.py file in an editor.

2.
Add the following URL pattern, before you include django.contrib.admin.urls, to override the admin/logout URL:

(r'^admin/logout/$', 'iFriends.Home.views.logout_user'),

3.
Save the iFriends/urls.py file.

4.
Access any page in the admin interface, and click the Logout link in the browser. You should be redirected to the login page, shown in Figure 18.6, instead of the normal Django admin page.

Figure 18.6. The iFriends custom Login page for the admin interface.



Previous Page Next Page