سؤال

An app I have been hired to work on is using django-permission.

Every view in the application requires authentication, but I need to create a simple way so I can have endpoints that doesn't require authentication. One usecase is for /callbacks.

I would like to create a custom decorator that I can use for such views.

Any hints or examples?

What I would prefer is:

@permission_required('none')
def callback_transloadit(request, pres_id):
هل كانت مفيدة؟

المحلول

This is how I solved it:

from django.contrib.auth.decorators import user_passes_test
from django.views.decorators.csrf import csrf_exempt


def allow_all(self):
    return True

@user_passes_test(allow_all)
@csrf_exempt
def callback_transloadit(request, pres_id):
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top