[Answer]-How to authenticate a user in Django?

1👍

Make a function login_page , check the authentication of the user there, if authenticated, redirect it to dashboard, else return to the login page.
Map this function to the login url in urls.py

def login_page(request):

    if request.user.is_authenticated():
        return redirect('/dashboard/')
    else:
        return login(request)

And then map this function to the login url.

url(r'login', 'modules.energy.login.views.login_page', name = 'cilantro_login'),

0👍

You may try this:

Whenever the user clicks the login page link, the view for the login page is executed. In that view, check if the user is logged in. If the user is logged in,, then redirect him to the dashboard, else display the login page. It is as simple as it is. The sample code:

if request.user.is_authenticated():
    #load dashboard
else:
    #load login page

Leave a comment