Background Image
Table of Contents Table of Contents
Previous Page  56 / 478 Next Page
Information
Show Menu
Previous Page 56 / 478 Next Page
Page Background

superlists/urls.py.

from

django.conf.urls

import

patterns

,

include

,

url

from

django.contrib

import

admin

urlpatterns

=

patterns

(

''

,

# Examples:

# url(r'^$', 'superlists.views.home', name='home'),

# url(r'^blog/', include('blog.urls')),

url

(

r'^admin/'

,

include

(

admin

.

site

.

urls

)),

)

As usual, lots of helpful comments and default suggestions from Django.

A

url

entry starts with a regular expression that defines which URLs it applies to, and

goes on to say where it should send those requests—either to a dot-notation encoded

function like

superlists.views.home

, or maybe to another

urls.py

file somewhere else

using

include

.

You can see there’s one entry in there by default there for the admin site. We’re not using

that yet, so let’s comment it out for now:

superlists/urls.py.

from

django.conf.urls

import

patterns

,

include

,

url

from

django.contrib

import

admin

urlpatterns

=

patterns

(

''

,

# Examples:

# url(r'^$', 'superlists.views.home', name='home'),

# url(r'^blog/', include('blog.urls')),

# url(r'^admin/', include(admin.site.urls)),

)

The first entry in

urlpatterns

has the regular expression

^$

, which means an empty

string—could this be the same as the root of our site, which we’ve been testing with “/”?

Let’s find out—what happens if we uncomment that line?

If you’ve never come across regular expressions, you can get away

with just taking my word for it, for now—but you should make a

mental note to go learn about them.

28

|

Chapter 3: Testing a Simple Home Page with Unit Tests