Home  >  Q&A  >  body text

How to skip login in python django admin management background

The admin management background that comes with the Django framework can be automatically logged in without logging in or opening the login page.
I don’t know how to start, please ask for guidance

phpcn_u1582phpcn_u15822712 days ago654

reply all(1)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-18 10:48:22

    Excerpted from official documentation:
    login(request, user, backend=None)

    To log a user in, from a view, use login(). It takes an HttpRequest object and a User object. login() saves the user’s ID in the session, using Django’s session framework.

    Note that any data set during the anonymous session is retained in the session after a user logs in.

    This example shows how you might use both authenticate() and login():

    from django.contrib.auth import authenticate, login
    
    def my_view(request):
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
            # Redirect to a success page.
            ...
        else:
            # Return an 'invalid login' error message.
            ...

    After knowing the above, you can make a view for logging in, and then redirect to the admin page after logging in

    reply
    0
  • Cancelreply