How to set settings.LOGIN_URL to a view function name in Django 1.5+
Assuming you've set the path name in urls.py
, you can use 'application_name:view_name'
as the LOGIN_URL
value in settings.py
, like so:
application/urls.py
...
path('login/', views.login, name='login'),
...
project/settings.py
LOGIN_URL = 'application:login'
https://docs.djangoproject.com/en/2.1/ref/settings/#login-url
Django computes this url in django.contrib.auth.views:redirect_to_login function as:
resolved_url = resolve_url(login_url or settings.LOGIN_URL)
Therefore you should set it as string:
LOGIN_URL = 'my_app.views.sign_in'
Also in settings.py you can use reverse_lazy function:
from django.core.urlresolvers import reverse_lazy
LOGIN_URL = reverse_lazy('my_app.views.sign_in')
https://docs.djangoproject.com/en/1.5/ref/urlresolvers/#reverse-lazy