Previous Page Next Page

Updating the URLconf File to Allow Admin Access

The Django admin interface must be added to the URLconf file so that you can access it from a web browser. Django automatically puts the following line in the urls.py file. However, it is initially commented out and therefore is inactive:

(r'^admin/', include('django.contrib.admin.urls'))

Did you Know?

You don't have to use the default value of admin as the web location for the admin interface. You can specify any name you want. For example:

(r'^WebMaster/', include('django.contrib.admin.urls'))


Try It Yourself: Add Admin Access to the URLconf File

In this section, you enable access to the admin interface for a web browser by adding the default entry for the admin application to the urls.py file.

1.
From a console prompt, change to the root directory of the iFriends project.

2.
Open the iFriends\urls.py file in an editor.

3.
Find the urlpatterns setting, and uncomment the (r'^admin/', include('django.contrib.admin.urls')), pattern, as shown in the following snippet:

urlpatterns = patterns('',
    (r'^People/$', 'iFriends.People.views.index')
# Uncomment this for admin:
     (r'^admin/', include('django.contrib.admin.urls')),
)

4.
Save the file.

5.
Enter the following command to start the development server:

python manage.py runserver

6.
Access the http://127.0.0.1:8000/admin URL. You should see a web page similar to the one shown in Figure 3.1.

Figure 3.1. Login page for Django's admin interface.


7.
Log in to the admin site using the superuser name and password that you set up in Hour 2. You should see a web page similar to the one shown in Figure 3.2.

Figure 3.2. Main page for Django's admin interface.


From the main page in Django's admin interface, you can add users, groups, and sites and manage any objects that have had the admin interface activated.


Previous Page Next Page