| | 531 | One useful application of the callable object syntax can be seen when using |
|---|
| | 532 | decorators; this allows you to apply decorators to views *in your URLconf*:: |
|---|
| | 533 | |
|---|
| | 534 | from django.conf.urls.defaults import * |
|---|
| | 535 | from django.contrib.auth.decorators import login_required |
|---|
| | 536 | from django.views.decorators.cache import cache_page |
|---|
| | 537 | from mysite.views import archive, about, contact |
|---|
| | 538 | |
|---|
| | 539 | urlpatterns = patterns('', |
|---|
| | 540 | (r'^archive/$', login_required(archive)), |
|---|
| | 541 | (r'^about/$', cache_page(about, 600)), |
|---|
| | 542 | (r'^contact/$', contact), |
|---|
| | 543 | ) |
|---|
| | 544 | |
|---|
| | 545 | Note that in this case you can't use the string syntax to specify the view |
|---|
| | 546 | parameter to the decorator itself, you must use the callable object |
|---|
| | 547 | syntax. |
|---|
| | 548 | |
|---|