Multiple decorators for a view in Django: Execution order

后端 未结 4 2043
温柔的废话
温柔的废话 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:33

    It only really makes sense to stack decorators if they have truly unique functionality. Based on your description, there's never going to be a scenario where you will want to use active_required but not login_required. Therefore, it makes more sense to have a login_and_active_required decorator that checks both and branches accordingly. Less to type, less to document, and negates the problem.

提交回复
热议问题