| 27 | | You can see that the first argument to ``patterns`` is an empty string in the |
|---|
| 28 | | above example, but that argument is actually very useful. The first argument |
|---|
| 29 | | will be prepended to all the view functions in the urlpatterns list, so the |
|---|
| 30 | | above example could be written more concisely as:: |
|---|
| | 27 | The first argument to ``patterns`` is an empty string in the above example, but |
|---|
| | 28 | that argument can be useful. The first argument is prepended to all the view |
|---|
| | 29 | functions in the urlpatterns list, so the above example could be written more |
|---|
| | 30 | concisely as:: |
|---|
| 46 | | You can also "include" other URL config modules at any point along the path. |
|---|
| 47 | | This essentially "roots" a set of URLs below other ones. This is most often |
|---|
| 48 | | used for a site's "base" URLconfig; the ``ROOT_URLCONF`` setting points to a |
|---|
| 49 | | urlconf module that will be used for the entire site. Here's the URLconf |
|---|
| 50 | | for the `Django website`_ itself. It includes a number of other URLconfs:: |
|---|
| | 46 | You can also "include" other URLconf modules at any point along the path. This |
|---|
| | 47 | essentially "roots" a set of URLs below other ones. This is most often used |
|---|
| | 48 | for a site's "base" URLconf; the ``ROOT_URLCONF`` setting points to a urlconf |
|---|
| | 49 | module that will be used for the entire site. Here's the URLconf for the |
|---|
| | 50 | `Django website`_ itself. It includes a number of other URLconfs:: |
|---|
| | 61 | |
|---|
| | 62 | Note that an included URLconf receives any captured parameters from parent |
|---|
| | 63 | URLconfs, so the following example is valid:: |
|---|
| | 64 | |
|---|
| | 65 | # In settings/urls/main.py |
|---|
| | 66 | urlpatterns = patterns('', |
|---|
| | 67 | (r'^(?P<username>\w+)/blog/', include('foo.urls.blog')), |
|---|
| | 68 | ) |
|---|
| | 69 | |
|---|
| | 70 | # In foo/urls/blog.py |
|---|
| | 71 | urlpatterns = patterns('foo.views' |
|---|
| | 72 | (r'^$', 'blog.index'), |
|---|
| | 73 | (r'^archive/$', 'blog.archive'), |
|---|
| | 74 | |
|---|
| | 75 | In the above example, the captured ``"username"`` variable is passed to the |
|---|
| | 76 | included URLconf, as expected. |
|---|