Learn Django

Create the URL Conf

The last step required to allow users to view the home page is to create the URL configuration. Follow these steps to enable that functionality.

Open /.../crmeasy/crmapp/urls.py in your IDE and edit it as follows.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from django.conf.urls import patterns, include, url

from marketing.views import HomePage

urlpatterns = patterns('',

    # Marketing pages
    url(r'^$', HomePage.as_view(), name="home"),

    # Subscriber related URLs


    # Admin URL


    # Login/Logout URLs


    # Account related URLs


    # Contact related URLS


    # Communication related URLs

)

Code Review

Line 1: This imports three modules included in Django that will be used as the urls.py file is built.

Line 3: This imports the HomePage view that was created in a previous lesson. This is required so that the view can be used in the URL configuration below.

Line 5: This line creates a list named urlpatterns. When Django processes requests it specifically looks for the urls.py file, and for the urlpatterns list. Both are required.

Line 8: This is the actual URL configuration for the home page. It passes three values to the url function. The first value is the URL path itself. This specific configuration will mean that this rule will be processed when a user goes to http://example.com/.

The second value is the view that we want to be accessed when this URL is accessed. The last value is a friendly name that we assign this URL configuration.

Remaining Lines: Comments to mark where other URL configurations will be placed.

Commit Changes

Execute these commands to commit your changes in Git.

1
2
3
4
5
# add files
(venv)$ git add .

# commit files
(venv)$ git commit -m "created the home page URL conf"

Track your progress with a free account