使用%login_required装饰器,用户未登录会自动转向登录界面。有时默认的登录URL并不是我们需要的,因此需要重新设置登录URL。
setting中添加一行:
LOGIN_URL = '/login/'
The URL or named URL pattern where requests are redirected for login when using the login_required() decorator, LoginRequiredMixin, or AccessMixin.