{"record":{"id":"66ecac322ef23485","repo":"django/django","slug":"self-class-name-is-missing-the-login-url","errorCode":null,"errorMessage":"{self.__class__.__name__} is missing the login_url attribute. Define {self.__class__.__name__}.login_url, settings.LOGIN_URL, or override {self.__class__.__name__}.get_login_url().","messagePattern":"(.+?) is missing the login_url attribute\\. Define (.+?)\\.login_url, settings\\.LOGIN_URL, or override (.+?)\\.get_login_url\\(\\)\\.","errorType":"exception","errorClass":"ImproperlyConfigured","httpStatus":null,"severity":"error","filePath":"django/contrib/auth/mixins.py","lineNumber":27,"sourceCode":"\nclass AccessMixin:\n    \"\"\"\n    Abstract CBV mixin that gives access mixins the same customizable\n    functionality.\n    \"\"\"\n\n    login_url = None\n    permission_denied_message = \"\"\n    raise_exception = False\n    redirect_field_name = REDIRECT_FIELD_NAME\n\n    def get_login_url(self):\n        \"\"\"\n        Override this method to override the login_url attribute.\n        \"\"\"\n        login_url = self.login_url or settings.LOGIN_URL\n        if not login_url:\n            raise ImproperlyConfigured(\n                f\"{self.__class__.__name__} is missing the login_url attribute. Define \"\n                f\"{self.__class__.__name__}.login_url, settings.LOGIN_URL, or override \"\n                f\"{self.__class__.__name__}.get_login_url().\"\n            )\n        return str(login_url)\n\n    def get_permission_denied_message(self):\n        \"\"\"\n        Override this method to override the permission_denied_message\n        attribute.\n        \"\"\"\n        return self.permission_denied_message\n\n    def get_redirect_field_name(self):\n        \"\"\"\n        Override this method to override the redirect_field_name attribute.\n        \"\"\"\n        return self.redirect_field_name","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/django/django/blob/b5388a3a80cafcce2e34196d8e81cf5b48eb33bb/django/contrib/auth/mixins.py#L9-L45","documentation":"Raised by AccessMixin.get_login_url() (mixins.py:21-31) as ImproperlyConfigured when neither the view's login_url attribute nor settings.LOGIN_URL is set. The login-required / permission-required mixins call get_login_url() inside handle_no_permission() to know where to redirect unauthenticated users. Without a login URL the redirect is impossible, so Django refuses to guess.","triggerScenarios":"A class-based view using LoginRequiredMixin, PermissionRequiredMixin, or UserPassesTestMixin receives an unauthenticated request, dispatch() calls handle_no_permission(), which calls get_login_url(), and both self.login_url (default None) and settings.LOGIN_URL (default None) are falsy. The f-string names the offending class.","commonSituations":"New project that hasn't set LOGIN_URL yet. A CBV with a loginRequiredMixin but the developer forgot to set LOGIN_URL in settings. Switching from a project-level login_url to a per-view one and removing the setting. LoginRequiredMixin added to a view during a refactor without updating settings.","solutions":["Set LOGIN_URL in settings.py (e.g. LOGIN_URL = '/accounts/login/').","Alternatively set login_url as a class attribute on the view (e.g. login_url = '/login/').","Or override get_login_url() on the view to compute the URL dynamically.","Run Django's system check framework (manage.py check) during CI to catch missing auth configuration early."],"exampleFix":"# settings.py — BEFORE\n# LOGIN_URL not set\n# settings.py — AFTER\nLOGIN_URL = \"/accounts/login/\"\n# OR per-view\nclass MyView(LoginRequiredMixin, View):\n    login_url = \"/login/\"","handlingStrategy":"validation","validationCode":"from django.conf import settings\n\nLOGIN_URL = getattr(settings, \"LOGIN_URL\", None)\nif not LOGIN_URL:\n    raise SystemExit(\"Set LOGIN_URL in settings before enabling login-required mixins.\")","typeGuard":null,"tryCatchPattern":"# Do not catch ImproperlyConfigured from get_login_url in dispatch.\n# Instead guarantee login_url or settings.LOGIN_URL is set.","preventionTips":["Set LOGIN_URL as a project-wide default in settings.","For APIs, set login_url per-view to avoid depending on the global.","Add `manage.py check` to CI to catch missing auth settings."],"tags":["django","authentication","cbv","configuration","mixin"],"backgroundTag":null,"analyzedSha":"b5388a3a80cafcce2e34196d8e81cf5b48eb33bb","analyzedAt":"2026-08-10T17:37:52.993Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}