0

I know the relative url (ie. /accounts/) and from that I'd like to determine whether or not the view that handles it is decorated with the login_required decorator.

KrisF
  • 1,331
  • 11
  • 26
  • 1
    Possible duplicate of [Check if a function has a decorator](http://stackoverflow.com/questions/5489649/check-if-a-function-has-a-decorator) – jatinderjit Nov 15 '16 at 22:03

1 Answers1

0

You can get the corresponding view from an URL using django.urls.resolve.

As of determining how it was decorated, this is impossible. A decorator is the application of a function, not some sort of flag.

However you can redefine your own login_required decorator that calls the original login_required AND sets a custom attribute to the view: view.is_login_required = True.

Antoine Pinsard
  • 28,811
  • 7
  • 58
  • 82