Previous Page Next Page

Setting Up the URLConf File

This section discusses configuring the URLConf file to define how installed applications are accessed from the web. The URLConf file is a Python script that allows you to define specific views that are accessed based on the URL that is sent by the web browser. When the Django server receives an URL request, it parses the request based on the patterns that are contained in the URLConf file. The parsed request is translated into a specific Python function that is executed in the views.py file, discussed in a moment.

By the Way

The location of the URLConf file is defined by the ROOT_URLCONF setting in the settings.py file. The default location is the name of the project's root directory. In the case of the iFriends project, the value of ROOT_URLCONF would be set to the following value, where 'iFriends.urls' equates to iFriends/urls.py:

ROOT_URLCONF = 'iFriends.urls'


Try It Yourself: Add an URL Pattern to Use for a People View

In this example, you set up a simple URL pattern for the People application by modifying the urlpatterns setting in the iFriends/urls.py file.

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

2.
Find the urlpatterns setting, and add the iFriends.People.views.index pattern to it:

urlpatterns = patterns('',
    (r'^People/$', 'iFriends.People.views.index')
)

3.
Save the file.

By the Way

In the preceding code snippet, iFriends.People.views.index refers to the index() function located in the iFriends/People/views.py file, which is discussed next.



Previous Page Next Page