0
所以基本上我的問題是,我用系統內置的dajngo驗證用戶後,用戶切換到用戶「admin」保持前一個用戶進入會話。代碼:django - 身份驗證:用戶在通過後續視圖時變成「admin」用戶
from django.contrib.auth import authenticate
from django.contrib.auth.decorators import login_required
def new_login_view(request):
if request.method == 'POST':
data = dict(request.POST)
data.pop('csrfmiddlewaretoken')
id_client = data['lg_username'][0]
pass_client = data['lg_password'][0]
user = authenticate(username=id_client, password=pass_client)
if user is not None:
# A backend authenticated the credentials
...
return render(request, 'initial_page.html', dictionary_with_info)
當我在initial_page.html
並激活一個觀點,那就是:
@login_required
def home(request):
if request.method == 'POST':
...
時,我呼籲request.user
我得到:User: admin
,而不是之前的用戶。
有什麼想法爲什麼?
你是那麼對! – Asher11