员工用户在未明确分配的情况下无权访问管理站点

我使用的是 Django 3.1.2,超级用户在管理站点中添加的员工用户在登录后无法访问同一管理站点。/admin/ 中的所有页面都会返回 403 禁止错误。


我在虚拟环境 (venv) 中使用 Windows 10、Python 3.8.5。我的命令是在 Git Bash 中发出的。它首先发生在其他项目中,所以我创建了一个新项目来尝试。Firefox、Edge 和 Chrome 中也会出现同样的错误。


正是我所做的:


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/login

Add 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

结果:

https://img1.sycdn.imooc.com/6539d1bf0001302d19170966.jpg

git 重击:

[09/Oct/2020 12:49:39] "GET /admin/ HTTP/1.1" 200 2282

其他网址:

https://img1.sycdn.imooc.com/6539d1cc0001eada19190969.jpg

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秒到达战场
浏览 99回答 1
1回答

largeQ

事情应该是这样的。您的新员工用户没有任何添加或编辑任何内容的权限。尝试创建一个具有一组权限的新组(例如添加/编辑用户或其他模型),然后将您的员工用户添加到该组。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python