Ad

Django Authentication Fail Search For Registration/login.html

- 1 answer

I try to add authentication for a page.

In my main url.py, i added:

url(r'^accounts/login/$', auth_views.login, {'template_name': 'test/login.html'}),

and in my view:

@login_required()
def result(request):
    ...

When I try to see the result view I am sent to the login page (good). When i enter a bad login/password there is an error because the template registration/login.html does not exist.

Why does django look for this template while I tell it to use test/login.html?

Ad

Answer

Try adding URL name

 url(r'^accounts/login/$', auth_views.login, {'template_name': 'test/login.html'}, name='login'),

This occurs because login view may use reverse('login') for redirect after failed login.

Ad
source: stackoverflow.com
Ad