Multiple decorators for a view in Django: Execution order

后端 未结 4 2029
温柔的废话
温柔的废话 2020-12-24 01:31

I am trying to decorate a Django view by two decorators, one for checking login, and one for checking is_active.

The first one is the built-in @login_required<

4条回答
  •  春和景丽
    2020-12-24 02:29

    To explain it a bit more (I was also confused at first): active_required is applied first in a sense that it takes my_view and wraps it in some code. Then login_required is applied and wraps the result in some more code.

    But when this wrapped version of my_view is actually invoked, first the code added by login_required is executed (checking that you're logged in), then the code added by active_required is executed (checking that you're active) and then finally my_view is executed.

提交回复
热议问题