Reputation: 121
So I'm using django.contrib.auth.urls and I would prefer to continue that. But I want the accounts/login url to be replaced with users/c-login or whatever.
I would really like to understand why this is not working:
my urls.py (project):
from core import views
urlpatterns = [
path("admin/", admin.site.urls),
path("accounts/", include("django.contrib.auth.urls")),
path("", include("core.urls")),
path("user/", include("user.urls")),
path("accounts/login", views.atest, name="login"),
path("accounts/login/", views.atest, name="login"),
]
The idea here was that
path("accounts/login/", views.atest, name="login"),
should "replace" the django auth urls.
views.py user app:
def atest(request):
return redirect("c-login")
And the custom login views.py user app:
def custom_login(request):
template_name = "registration/login.html"
Any help appreciated. Thanks
Upvotes: 1
Views: 45
Reputation: 121
Comment from raphael answers the question 100%! Django looks at your url patterns in order until it finds one that matches, so path("accounts/login", views.atest, name="login") will not ever be seen because path("accounts/", include("django.contrib.auth.urls")) matches first. Having said that, if all you want to do is create a user registration page, or style the login page, then you don't need this.
Check out developer.mozilla.org/en-US/docs/Learn/Server-side/Django/… (especially developer.mozilla.org/en-US/docs/Learn/Server-side/Django/…) –
Upvotes: 0