python django admin管理後台跳過登錄,怎麼做
phpcn_u1582
phpcn_u1582 2017-05-18 10:46:22
0
1
709

django框架自帶的admin管理後台,想做成不需要登入或開啟登入頁面時,可以自動登錄,
不知道如何下手,求大神指導

phpcn_u1582
phpcn_u1582

全部回覆(1)
给我你的怀抱

摘自官方文件:
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.
        ...

知道了上面這些之後,你自己就可以做個用來登入的view,在裡面登入完之後再redirect到admin頁面就好了

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板