# decorator @login\_required does not come back to login page

**URL:** <https://forum.djangoproject.com/t/decorator-login-required-does-not-come-back-to-login-page/45659>\
**Category:** Mystery Errors\
**Created:** [August 3, 2026, 8:14am UTC](https://forum.djangoproject.com/t/decorator-login-required-does-not-come-back-to-login-page/45659 "2026-08-03T08:14:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chesapeakebayy-sketc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/chesapeakebayy-sketc/32/32796_2.png) [@chesapeakebayy-sketc](https://forum.djangoproject.com/u/chesapeakebayy-sketc)\
**Post date:** [August 3, 2026, 8:14am UTC](https://forum.djangoproject.com/t/decorator-login-required-does-not-come-back-to-login-page/45659/1 "2026-08-03T08:14:26Z")

</div>

I am using:

from django.contrib.auth.decorators import login\_required

so I have defined a view for user profiles, but obviously, this one must be only accessed whenever its user is logged in, otherwise, the login page should be displayed…

However I obtain the following error message…

# NoReverseMatch at /users/profile/

```auto
Reverse for 'login' not found. 'login' is not a valid view function or pattern name.

```

| Request Method: | GET |
| --- | --- |
| Request URL: | [http://127.0.0.1:8000/users/profile/](http://127.0.0.1:8000/users/profile/) |
| Django Version: | 6.0.6 |
| Exception Type: | NoReverseMatch |
| Exception Value: | |

```auto
Reverse for 'login' not found. 'login' is not a valid view function or pattern name.

```

does someone know to fix this issue…?

---

<div class="post-metadata">

**Author:** ![stuartmaxwell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/stuartmaxwell/32/1135_2.png) [@stuartmaxwell](https://forum.djangoproject.com/u/stuartmaxwell)\
**Post date:** [August 3, 2026, 10:02am UTC](https://forum.djangoproject.com/t/decorator-login-required-does-not-come-back-to-login-page/45659/2 "2026-08-03T10:02:00Z")

</div>

You don’t have your auth URLs included in your URL patterns. You need to add something like this: `path("accounts/", include("django.contrib.auth.urls")),` to your URL config.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 3, 2026, 11:02am UTC](https://forum.djangoproject.com/t/decorator-login-required-does-not-come-back-to-login-page/45659/3 "2026-08-03T11:02:27Z")

</div>

You don’t have a URL defined with `name="login"`

See the docs at [Using the Django authentication system | Django documentation | Django](https://docs.djangoproject.com/en/6.0/topics/auth/default/#the-login-required-decorator) for how you need to configure your URLs to use the decorator.

If you think you have configured everything correctly, please post those items here - you may have an error in what you have done.

Also, please watch the profanity. This is intended to be a professional setting and such language does not add to the conversation.

---

<div class="post-metadata">

**Author:** ![louzolo123](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/louzolo123/32/32811_2.png) [@louzolo123](https://forum.djangoproject.com/u/louzolo123)\
**Post date:** [August 3, 2026, 11:26am UTC](https://forum.djangoproject.com/t/decorator-login-required-does-not-come-back-to-login-page/45659/4 "2026-08-03T11:26:17Z")

</div>

Hi chief

This error doesn’t come from your profile view itself it comes from @login\_required trying to build the redirect to your login page.

When an unauthenticated user hits a @login\_required view, Django redirects them to settings.LOGIN\_URL. If that setting is a URL name (like `‘login’`), Django reverses it to build the redirect. Since there’s no URL pattern named login in your project, the reverse fails and you get NoReverseMatch and it shows up on /users/profile/ because that’s the exact spot where the redirect is being constructed

---

<div class="post-metadata">

**Author:** ![chesapeakebayy-sketc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/chesapeakebayy-sketc/32/32796_2.png) [@chesapeakebayy-sketc](https://forum.djangoproject.com/u/chesapeakebayy-sketc)\
**Post date:** [August 3, 2026, 11:28am UTC](https://forum.djangoproject.com/t/decorator-login-required-does-not-come-back-to-login-page/45659/5 "2026-08-03T11:28:52Z")

</div>

Touché: I have just set up the LOGIN\_URL in file settings.py and it works…thank you very much for your help (all…)

---

<div class="post-metadata">

**Author:** ![louzolo123](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/louzolo123/32/32811_2.png) [@louzolo123](https://forum.djangoproject.com/u/louzolo123)\
**Post date:** [August 3, 2026, 5:35pm UTC](https://forum.djangoproject.com/t/decorator-login-required-does-not-come-back-to-login-page/45659/6 "2026-08-03T17:35:09Z")

</div>

You’re welcome guy

That’s perfect
