url - Django permissions checks at urlconf level? -
i've got django app has it's own urlconf included main one. every page in app protected separate set of perms not granted normal users. think employees work view opposed users' profiles etc.
i'm using classed based views, right i've got landing view's dispatch() checking perms, method i'm going have every view. isn't dry.
so options see them are:
- create mixin checks permission
- manually check using dispatch() in each view
- somehow check @ url level
is there way set permission requirement on entire url inclusion? have login_required() on.
easy!
from django.contrib.auth.decorators import login_required urlpatterns = patterns('', url(r'^foo/', login_required(include('foo.urls'))), )
update
you want check user permissions, not user authentication. easy too:
from django.contrib.auth.decorators import user_passes_test urlpatterns = patterns('', url(r'^foo/', user_passes_test(lambda u: u.has_perm('perm'))(include('foo.urls'))), )
Comments
Post a Comment