我想检查用户是否对某些URL授权。我正在使用通用视图。
这里的文档说可以将login_required作为可选参数传递,但我不确定。可能是这样:(r'^$', 'archive_index', link_info_dict, 'coltrane_link_archive_index', login_required=True,),
我想在URL中使用login_required修饰符。这可行吗?我该怎么做?
from django.conf.urls.defaults import *
from coltrane.models import Link
link_info_dict = {
'queryset': Link.live.all(),
'date_field': 'pub_date',
}
urlpatterns = patterns('django.views.generic.date_based',
(r'^$', 'archive_index', link_info_dict, 'coltrane_link_archive_index'),
(r'^(?P<year>\d{4})/$', 'archive_year', link_info_dict, 'coltrane_link_archive_year'),
(r'^(?P<year>\d{4})/(?P<month>\w{3})/$', 'archive_month', link_info_dict, 'coltrane_link_archive_month'),
(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/$', 'archive_day', link_info_dict, 'coltrane_link_archive_day'),
(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 'object_detail', link_info_dict, 'coltrane_link_detail'),
)
例如,我该如何保护这个页面(没有视图可以添加login_Required装饰器)?
(r'^$', 'django.views.generic.simple.direct_to_template', {
'template': 'home.html'
}, ),