我使用的是 Django 3.1.2,超級用戶在管理站點中添加的員工用戶在登錄后無法訪問同一管理站點。/admin/ 中的所有頁面都會返回 403 禁止錯誤。我在虛擬環(huán)境 (venv) 中使用 Windows 10、Python 3.8.5。我的命令是在 Git Bash 中發(fā)出的。它首先發(fā)生在其他項目中,所以我創(chuàng)建了一個新項目來嘗試。Firefox、Edge 和 Chrome 中也會出現(xiàn)同樣的錯誤。正是我所做的:git 重擊:$ mkdir test_staff$ cd test_staff/$ python -m venv venv_dev$ source venv_dev/Scripts/activate$ pip install Django==3.1.2$ pip list Package Version ---------- ------- asgiref 3.2.10 Django 3.1.2 pip 20.1.1 pytz 2020.1 setuptools 47.1.0 sqlparse 0.4.1$ django-admin startproject mysite$ cd mysite/$ python manage.py migrate$ winpty python manage.py createsuperuser username: admin password: 12345$ python manage.py runserver瀏覽器:Login with "admin" user: http://localhost:8000/admin/loginAdd staff user: http://localhost:8000/admin/auth/user/add/ username: staff_user password: Ax47y](U[1fpw;8H2?}) > Save and continue editing staff status = True > Save Logout: http://localhost:8000/admin/logout/Login with "staff_user": http://localhost:8000/admin/login結果:git 重擊:[09/Oct/2020 12:49:39] "GET /admin/ HTTP/1.1" 200 2282其他網址:git 重擊:Forbidden (Permission denied): /admin/auth/user/Traceback (most recent call last):File "C:\Users\DELL\Documents\github\test_staff\venv_dev\lib\site-packages\django\core\handlers\exception.py", line 47, in inner response = get_response(request)File "C:\Users\DELL\Documents\github\test_staff\venv_dev\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs)File "C:\Users\DELL\Documents\github\test_staff\venv_dev\lib\site-packages\django\contrib\admin\options.py", line 614, in wrapper return self.admin_site.admin_view(view)(*args, **kwargs)如果我明確向用戶分配身份驗證權限,則員工用戶只能訪問管理站點。
員工用戶在未明確分配的情況下無權訪問管理站點
30秒到達戰(zhàn)場
2023-10-26 10:40:36