A
A
Alex Pavlichenko2017-05-12 14:15:37
Django
Alex Pavlichenko, 2017-05-12 14:15:37

How to do user authorization in django?

Wrote authorization using guides

def auth(request):
    if request.user.is_authenticated():
        return redirect('account/')
    elif request.method == 'POST':
        form_auth = AuthenticationForm(request=request, data=request.POST)
        if form_auth.is_valid():
            user = form_auth.get_user()
            AUTH.login(request, user)
            return redirect("account/")
    else:
        form_auth = AuthenticationForm()
        return render(request, "lk/auth.html", {'form_auth': form_auth})

If at this time you log in to the admin panel, then when you go to the pages of the site, the user remains logged in. If you exit the admin panel and log in to the site, then after going to the pages of the site that are not related to your personal account, the user logs out. How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CompiBox, 2017-05-12
@compibox

Write your middleware and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question