diff -r 04db33c299a1 docs/url_dispatch.txt
a
|
b
|
Note that if you use this technique -- p
|
528 | 528 | Note that if you use this technique -- passing objects rather than strings -- |
529 | 529 | the view prefix (as explained in "The view prefix" above) will have no effect. |
530 | 530 | |
| 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 | |
531 | 549 | Naming URL patterns |
532 | 550 | =================== |
533 | 551 | |