python - Django permissions: Access to only one view method among many -


hi have project many methods in view. each method mapped different urls.

views.py

def method1(request):     print 'hello world'  def method2(request):     print 'hello world2'  def method3(request):     print 'hello world3' 

what want related permission user can access 1 method. e.g if user has permission method2(), he/she can access method. he/she mustn't access method1() or method2().

like described here https://djangosnippets.org/snippets/1703/, can use user_pass_test() function in way can restrict one.

if want restrict except 1 have apply decorators in existing methods , there alot of methods in project.

here want restrict except one.

please help.

django's permissions might or not right way tell if given user can access given view, don't tell enough context.

but anyway... there 2 solutions here: either decorate each , every view appropriate user_passes_test(yourtesthere) or permission_required(perm) decorator, or use custom middleware process_view method.


Comments