python django admin管理后臺跳過登錄,怎么做
問題描述
django框架自帶的admin管理后臺,想做成不需要登錄或者打開登錄頁面時,可以自動登錄,不知道如何下手,求大神指導(dǎo)
問題解答
回答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, logindef 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頁面就好了
相關(guān)文章:
1. javascript - 豆瓣的這個自適應(yīng)是怎么做的?2. 大家好,我想請問一下怎么做搜索欄能夠搜索到自己網(wǎng)站的內(nèi)容。3. javascript - 一個很特殊的跳轉(zhuǎn)方式,想問問怎么做到的!4. javascript - js(Vue)實(shí)踐:怎么做出輸入@,然后自動出現(xiàn)相關(guān)人選的列表?5. css - 404頁面怎么做6. python 中對redis 操作采用裝飾器進(jìn)行處理,怎么做7. angular.js - webpack怎么做到liveload?8. css3 - css背景圖片高度百分百,寬度保持比例怎么做?9. javascript - 在一些視頻為主的h5頁面中,是怎么做到獲取視頻緩沖進(jìn)度或者說如何對video視頻做預(yù)加載的10. php - 怎么做一個用戶消息提醒功能,就是不用刷新頁面的。
