Reputation: 673
I've use a tutorial to implement authentification (app registration) and it works but I do not understand well
I have declare registration url in the django project
myproject/urls.py
path('registration/', include('django.contrib.auth.urls')),
So authentification use default LoginViews, LogoutViews...
I have also declare (below) but these urls are not used as even if I suppress these urls autentifications still works...
what is the corect way of authentification?
registration/views.py
from . import views
from django.contrib.auth import views as auth_views
app_name='registration'
urlpatterns = [
path('login/', views.login, name='login'),
path('logout/', views.logout, name='logout'),
]```
Upvotes: 0
Views: 79
Reputation: 20672
You just need to define the urls in the correct order. Django reads the routes from top to bottom and the first match is taken.
If for example you only want to override the login view, you can do this in your project's urls.py:
path('registration/login/', my_views.login, name="login"),
path('registration/', include('django.contrib.auth.urls')),
If you want to override more views, I'd rather redefine all the urls from django.contrib.auth.urls in your registration/urls.py. In that case, do this:
# project urls.py
from registration import urls as registration_urls
path('registration', include(registration_urls)),
# registration/urls.py
from django.contrib.auth import views as auth_views
from . import views as my_views
# ...
path('login', my_views.login, name="login"),
path('logout', my_views.logout, name="logout"),
# ...
path('password_change/', auth_views.PasswordChangeView.as_view(), name='password_change'),
path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(), name='password_change_done'),
path('password_reset/', auth_views.PasswordResetView.as_view(), name='password_reset'),
path('password_reset/done/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
path('reset/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
path('reset/done/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
# ...
Upvotes: 1