houndy
houndy

Reputation: 13

Django password_change redirect to broken link

[Edit] SOLVED, but I still wouldn't mind an answer as to why. I had to add:

LOGIN_URL = '/users/login'

to settings.py. So why doesn't django use the "django.contrib.auth.urls" subdirectory?

[Original question below] I'm following the Django for Beginners book, Ch11 password change. Here's my problem: When the user is logged out and attempts to go to password_change: http://127.0.0.1:8000/users/password_change/ it redirects to http://127.0.0.1:8000/accounts/login/?next=/users/password_change/ and I get a 404, Page Not Found.

The book uses an app called 'accounts' but I prefer 'users' and I can't find any reference to 'accounts' in my files.

If the user is logged in, everything works properly, but in that case, there isn't a login redirect.

Here's my main question: why is django redirecting to http://127.0.0.1:8000/accounts/ for login?

Here is my django_project/urls.py

from django.contrib import admin
from django.urls import path
from django.urls import path, include 
from django.views.generic.base import TemplateView 

urlpatterns = [
    path("admin/", admin.site.urls),
    path("users/", include("users.urls")),  
    path("users/", include("django.contrib.auth.urls")),  
    path("", include("pages.urls")), 
]

And if I navigate to http://127.0.0.1:8000/users/, I get an expected 404 and the debug lists these URLs for login, which is what I expect:

Using the URLconf defined in django_project.urls, Django tried these URL patterns, in this order:

admin/
users/ signup/ [name='signup']
users/ login/ [name='login']
users/ logout/ [name='logout']
users/ password_change/ [name='password_change']
users/ password_change/done/ [name='password_change_done']
users/ password_reset/ [name='password_reset']
users/ password_reset/done/ [name='password_reset_done']
users/ reset/<uidb64>/<token>/ [name='password_reset_confirm']
users/ reset/done/ [name='password_reset_complete']
[name='home']
The current path, users/, didn’t match any of these.

Upvotes: 1

Views: 291

Answers (1)

Hashem
Hashem

Reputation: 645

you can add to settings.py this line

LOGIN_REDIRECT_URL = 'https://YourLoginUrl/'

Upvotes: 1

Related Questions