diff --git a/docs/intro/overview.txt b/docs/intro/overview.txt
index 34572a6..5b02f62 100644
a
|
b
|
decouple URLs from Python code.
|
176 | 176 | Here's what a URLconf might look like for the ``Reporter``/``Article`` |
177 | 177 | example above:: |
178 | 178 | |
179 | | from django.conf.urls.defaults import * |
| 179 | from django.conf.urls.defaults import patterns, url, include |
180 | 180 | |
181 | 181 | urlpatterns = patterns('', |
182 | 182 | (r'^articles/(\d{4})/$', 'news.views.year_archive'), |
diff --git a/docs/intro/tutorial02.txt b/docs/intro/tutorial02.txt
index c80d87d..d5f8728 100644
a
|
b
|
activate the admin site for your installation, do these three things:
|
43 | 43 | |
44 | 44 | .. parsed-literal:: |
45 | 45 | |
46 | | from django.conf.urls.defaults import * |
| 46 | from django.conf.urls.defaults import patterns, url, include |
47 | 47 | |
48 | 48 | # Uncomment the next two lines to enable the admin: |
49 | 49 | **from django.contrib import admin** |
diff --git a/docs/intro/tutorial03.txt b/docs/intro/tutorial03.txt
index 0843d9e..ce7e2ca 100644
a
|
b
|
point at that file::
|
78 | 78 | |
79 | 79 | Time for an example. Edit ``mysite/urls.py`` so it looks like this:: |
80 | 80 | |
81 | | from django.conf.urls.defaults import * |
| 81 | from django.conf.urls.defaults import patterns, url, include |
82 | 82 | |
83 | 83 | from django.contrib import admin |
84 | 84 | admin.autodiscover() |
… |
… |
It's just a normal view.
|
366 | 366 | You normally won't have to bother with writing 404 views. By default, URLconfs |
367 | 367 | have the following line up top:: |
368 | 368 | |
369 | | from django.conf.urls.defaults import * |
| 369 | from django.conf.urls.defaults import patterns, url, include |
370 | 370 | |
371 | 371 | That takes care of setting ``handler404`` in the current module. As you can see |
372 | 372 | in ``django/conf/urls/defaults.py``, ``handler404`` is set to |
… |
… |
callback in your URLconf, you can concatenate multiple
|
459 | 459 | :func:`~django.conf.urls.defaults.patterns`. Your full ``mysite/urls.py`` might |
460 | 460 | now look like this:: |
461 | 461 | |
462 | | from django.conf.urls.defaults import * |
| 462 | from django.conf.urls.defaults import patterns, url, include |
463 | 463 | |
464 | 464 | from django.contrib import admin |
465 | 465 | admin.autodiscover() |
… |
… |
Copy the file ``mysite/urls.py`` to ``polls/urls.py``. Then, change
|
496 | 496 | :func:`~django.conf.urls.defaults.include`, leaving you with:: |
497 | 497 | |
498 | 498 | # This also imports the include function |
499 | | from django.conf.urls.defaults import * |
| 499 | from django.conf.urls.defaults import patterns, url, include |
500 | 500 | |
501 | 501 | from django.contrib import admin |
502 | 502 | admin.autodiscover() |
… |
… |
URLconf by removing the leading "polls/" from each line, and removing the
|
526 | 526 | lines registering the admin site. Your ``polls.urls`` file should now look like |
527 | 527 | this:: |
528 | 528 | |
529 | | from django.conf.urls.defaults import * |
| 529 | from django.conf.urls.defaults import patterns, url, include |
530 | 530 | |
531 | 531 | urlpatterns = patterns('polls.views', |
532 | 532 | (r'^$', 'index'), |
diff --git a/docs/intro/tutorial04.txt b/docs/intro/tutorial04.txt
index 606da56..f036464 100644
a
|
b
|
Read on for details.
|
220 | 220 | First, open the ``polls/urls.py`` URLconf. It looks like this, according to the |
221 | 221 | tutorial so far:: |
222 | 222 | |
223 | | from django.conf.urls.defaults import * |
| 223 | from django.conf.urls.defaults import patterns, url, include |
224 | 224 | |
225 | 225 | urlpatterns = patterns('polls.views', |
226 | 226 | (r'^$', 'index'), |
… |
… |
tutorial so far::
|
231 | 231 | |
232 | 232 | Change it like so:: |
233 | 233 | |
234 | | from django.conf.urls.defaults import * |
| 234 | from django.conf.urls.defaults import patterns, url, include |
235 | 235 | from django.views.generic import DetailView, ListView |
236 | 236 | from polls.models import Poll |
237 | 237 | |
diff --git a/docs/topics/class-based-views.txt b/docs/topics/class-based-views.txt
index f0e4910..5c7f8d3 100644
a
|
b
|
views themselves are classes, we point the URL to the as_view class method
|
75 | 75 | instead, which is the entrypoint for class-based views:: |
76 | 76 | |
77 | 77 | # urls.py |
78 | | from django.conf.urls.defaults import * |
| 78 | from django.conf.urls.defaults import patterns, url, include |
79 | 79 | from some_app.views import AboutView |
80 | 80 | |
81 | 81 | urlpatterns = patterns('', |
… |
… |
Alternatively, if you're only changing a few simple attributes on a
|
86 | 86 | class-based view, you can simply pass the new attributes into the as_view |
87 | 87 | method call itself:: |
88 | 88 | |
89 | | from django.conf.urls.defaults import * |
| 89 | from django.conf.urls.defaults import patterns, url, include |
90 | 90 | from django.views.generic import TemplateView |
91 | 91 | |
92 | 92 | urlpatterns = patterns('', |
… |
… |
be using these models::
|
135 | 135 | |
136 | 136 | To build a list page of all publishers, we'd use a URLconf along these lines:: |
137 | 137 | |
138 | | from django.conf.urls.defaults import * |
| 138 | from django.conf.urls.defaults import patterns, url, include |
139 | 139 | from django.views.generic import ListView |
140 | 140 | from books.models import Publisher |
141 | 141 | |
diff --git a/docs/topics/generic-views.txt b/docs/topics/generic-views.txt
index 41e32c8..e24bb84 100644
a
|
b
|
URLconf tuple for a given pattern.
|
48 | 48 | For example, here's a simple URLconf you could use to present a static "about" |
49 | 49 | page:: |
50 | 50 | |
51 | | from django.conf.urls.defaults import * |
| 51 | from django.conf.urls.defaults import patterns, url, include |
52 | 52 | from django.views.generic.simple import direct_to_template |
53 | 53 | |
54 | 54 | urlpatterns = patterns('', |
… |
… |
the URLconf to point to a view function:
|
70 | 70 | |
71 | 71 | .. parsed-literal:: |
72 | 72 | |
73 | | from django.conf.urls.defaults import * |
| 73 | from django.conf.urls.defaults import patterns, url, include |
74 | 74 | from django.views.generic.simple import direct_to_template |
75 | 75 | **from books.views import about_pages** |
76 | 76 | |
… |
… |
be using these models::
|
150 | 150 | |
151 | 151 | To build a list page of all publishers, we'd use a URLconf along these lines:: |
152 | 152 | |
153 | | from django.conf.urls.defaults import * |
| 153 | from django.conf.urls.defaults import patterns, url, include |
154 | 154 | from django.views.generic import list_detail |
155 | 155 | from books.models import Publisher |
156 | 156 | |
diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt
index 6179c30..542ad79 100644
a
|
b
|
Example
|
59 | 59 | |
60 | 60 | Here's a sample URLconf:: |
61 | 61 | |
62 | | from django.conf.urls.defaults import * |
| 62 | from django.conf.urls.defaults import patterns, url, include |
63 | 63 | |
64 | 64 | urlpatterns = patterns('', |
65 | 65 | (r'^articles/2003/$', 'news.views.special_case_2003'), |
… |
… |
Here's a sample URLconf::
|
70 | 70 | |
71 | 71 | Notes: |
72 | 72 | |
73 | | * ``from django.conf.urls.defaults import *`` makes the ``patterns()`` |
| 73 | * ``from django.conf.urls.defaults import patterns, url, include`` makes the ``patterns()`` |
74 | 74 | function available. |
75 | 75 | |
76 | 76 | * To capture a value from the URL, just put parenthesis around it. |
… |
… |
Syntax of the urlpatterns variable
|
177 | 177 | ``django.conf.urls.defaults.patterns()``. Always use ``patterns()`` to create |
178 | 178 | the ``urlpatterns`` variable. |
179 | 179 | |
180 | | Convention is to use ``from django.conf.urls.defaults import *`` at the top of |
| 180 | Convention is to use ``from django.conf.urls.defaults import patterns, url, include`` at the top of |
181 | 181 | your URLconf. This gives your module access to these objects: |
182 | 182 | |
183 | 183 | patterns |
… |
… |
code duplication.
|
335 | 335 | |
336 | 336 | Here's the example URLconf from the :doc:`Django overview </intro/overview>`:: |
337 | 337 | |
338 | | from django.conf.urls.defaults import * |
| 338 | from django.conf.urls.defaults import patterns, url, include |
339 | 339 | |
340 | 340 | urlpatterns = patterns('', |
341 | 341 | (r'^articles/(\d{4})/$', 'news.views.year_archive'), |
… |
… |
each view function.
|
350 | 350 | |
351 | 351 | With this in mind, the above example can be written more concisely as:: |
352 | 352 | |
353 | | from django.conf.urls.defaults import * |
| 353 | from django.conf.urls.defaults import patterns, url, include |
354 | 354 | |
355 | 355 | urlpatterns = patterns('news.views', |
356 | 356 | (r'^articles/(\d{4})/$', 'year_archive'), |
… |
… |
Just add multiple ``patterns()`` objects together, like this:
|
371 | 371 | |
372 | 372 | Old:: |
373 | 373 | |
374 | | from django.conf.urls.defaults import * |
| 374 | from django.conf.urls.defaults import patterns, url, include |
375 | 375 | |
376 | 376 | urlpatterns = patterns('', |
377 | 377 | (r'^$', 'django.views.generic.date_based.archive_index'), |
… |
… |
Old::
|
381 | 381 | |
382 | 382 | New:: |
383 | 383 | |
384 | | from django.conf.urls.defaults import * |
| 384 | from django.conf.urls.defaults import patterns, url, include |
385 | 385 | |
386 | 386 | urlpatterns = patterns('django.views.generic.date_based', |
387 | 387 | (r'^$', 'archive_index'), |
… |
… |
essentially "roots" a set of URLs below other ones.
|
401 | 401 | For example, here's the URLconf for the `Django Web site`_ itself. It includes a |
402 | 402 | number of other URLconfs:: |
403 | 403 | |
404 | | from django.conf.urls.defaults import * |
| 404 | from django.conf.urls.defaults import patterns, url, include |
405 | 405 | |
406 | 406 | urlpatterns = patterns('', |
407 | 407 | (r'^weblog/', include('django_website.apps.blog.urls.blog')), |
… |
… |
Another possibility is to include additional URL patterns not by specifying the
|
421 | 421 | URLconf Python module defining them as the `include`_ argument but by using |
422 | 422 | directly the pattern list as returned by `patterns`_ instead. For example:: |
423 | 423 | |
424 | | from django.conf.urls.defaults import * |
| 424 | from django.conf.urls.defaults import patterns, url, include |
425 | 425 | |
426 | 426 | extra_patterns = patterns('', |
427 | 427 | url(r'reports/(?P<id>\d+)/$', 'credit.views.report', name='credit-reports'), |
diff --git a/docs/topics/http/views.txt b/docs/topics/http/views.txt
index 399e6b6..92cc8fc 100644
a
|
b
|
URLconf, like so::
|
143 | 143 | Behind the scenes, Django determines the 404 view by looking for ``handler404``. |
144 | 144 | By default, URLconfs contain the following line:: |
145 | 145 | |
146 | | from django.conf.urls.defaults import * |
| 146 | from django.conf.urls.defaults import patterns, url, include |
147 | 147 | |
148 | 148 | That takes care of setting ``handler404`` in the current module. As you can see |
149 | 149 | in ``django/conf/urls/defaults.py``, ``handler404`` is set to |
… |
… |
URLconf, like so::
|
191 | 191 | Behind the scenes, Django determines the error view by looking for ``handler500``. |
192 | 192 | By default, URLconfs contain the following line:: |
193 | 193 | |
194 | | from django.conf.urls.defaults import * |
| 194 | from django.conf.urls.defaults import patterns, url, include |
195 | 195 | |
196 | 196 | That takes care of setting ``handler500`` in the current module. As you can see |
197 | 197 | in ``django/conf/urls/defaults.py``, ``handler500`` is set to |