自己慢慢积累。
分类: Python/Ruby
2016-09-28 14:48:43
from django.conf.urls.defaults import * from mysite.views import requires_login, my_view1, my_view2, my_view3 urlpatterns = patterns('', url(r'^view1/$', requires_login(my_view1)), url(r'^view2/$', requires_login(my_view2)), url(r'^view3/$', requires_login(my_view3)), )
def requires_login(view): def new_view(request, *args, **kwargs): if not request.user.is_authenticated(): return HttpResponseRedirect('/accounts/login/') return view(request, *args, **kwargs) return new_view