url

Admin

Reversing admin URLs

(from The Definitive Guide to Django page 118, Special-Casing Views):

('^([^/]+)/([^/]+)/add/$', my_other_view),

…(if I typed it right)… this will (apparently) match URLs like /myblog/entries/add/ and /auth/groups/add/.

^

start of the string

\[^/\]

Match any character that is NOT a slash…

+

Between one and unlimited times.

Home Page (root)

(r'^/?$', temporary_home_page),

Numbers and arguments

(r'^time/plus/(\d{1,2})/$', my_other_view),

\d+

To match any number of digits.

\d{1,2}

To match one or two digits (maximum 99).

(\d{1,2})

Enclose arguments you want to define within brackets.

Parameters (and Name)

Including other URLconfs:

url(r'^artist/$',
    feature_index,
    { 'category': 'artist', },
    name='feature_index_artist'),

Note: See (My) Coding Standards, URL for the preferred way of using url.

Slug

For a nice URL sample, combining a date with a slug, see urls.py from simple_url_monitor.

(r'^news/(?P<slug>[-\w]+)/$', get_time_line),