[Fixed]-Django searches for a template in an unspecified location

0πŸ‘

βœ…

I had url(r'^', include('django.contrib.auth.urls')) mentioned above login and other urls. This is the reason, Django was looking for a template under /registration/login. I still don’t know why Django looks for a template in that location when the url is /login. When the url is accounts/login, no problems occur. I put url(r'^', include('django.contrib.auth.urls'))in the end of urlpatterns.

from django.conf import settings
from django.conf.urls import url, include
from django.conf.urls.static import static
from django.contrib import admin
from accounts.views import login_view, logout_view, register_view, reset_password_view

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^blog/', include('blog.urls')),
    url(r'^', include('personal.urls')), 
    url(r'^login/', login_view),
    url(r'^logout/', logout_view),
    url(r'^register/', register_view),
    url(r'^reset-password/', reset_password_view),
    url(r'^landing/', include('landing.urls')),
    url(r'^tracking/', include('tracking.urls')),
    url(r'^accounts/', include('accounts.urls')),
    url(r'^', include('django.contrib.auth.urls')),  # Put this in the end 
]
πŸ‘€sagar_jeevan

1πŸ‘

May be you should create urls.py for your app accounts?

accounts urls.py

from django.conf.urls import url

from . import views

urlpatterns = [
    # ex: /accounts/
    url(r'^login/', login_view),
]

in the main urls.py

from ...
urlpatterns = [
    ...
    url(r'^accounts/', include('yourwebsite.accounts.urls')),
    ....
]

and base.html

<a href="/accounts/login">Log In</a>
πŸ‘€Alex Pol

Leave a comment