【发布时间】:2016-03-01 10:11:35
【问题描述】:
文档功能nice options for applying decorators such as login_required to Class Based Views。
但是,我有点不清楚如何将特定参数与装饰器一起传递,在这种情况下,我想change the login_url of the decorator。
类似以下,仅有效:
@login_required(login_url="Accounts:account_login")
@user_passes_test(profile_check)
class AccountSelectView(TemplateView):
template_name='select_account_type.html'
【问题讨论】:
-
除了改变你使用装饰器的方式,你还需要反转登录url。当你在装饰器中使用它时,使用
reverse_lazy,即login_url=reverse_lazy("Accounts:account_login")。
标签: python django django-class-based-views python-decorators django-generic-views