python - Django 身份验证和权限 : Snippets visible only to the creator

标签 python django authentication permissions code-snippets

因此在身份验证和权限教程中:

http://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/

所有用户都可以看到所有片段,但只允许用户编辑自己的片段。

但我想稍微调整一下程序:

用户只能看到自己的片段。其他人创建的片段不可见。

这可能吗?

最佳答案

是的,这是可能的。看看filtering querysets 。简而言之,您必须编写自己的 get_queryset 方法,以仅返回与登录用户关联的结果。

关于python - Django 身份验证和权限 : Snippets visible only to the creator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36588546/

相关文章:

python - 使用Python获取语法错误

python - 无法将库导入项目

authentication - 使用 Azure AD 身份验证的 IIS 身份验证设置

python - 忽略 'usecol' 参数中的缺失列

python - 了解 Numpy 多维数组索引

python - 在 Django admin 中显示子级内联

python - Django 干草堆 : How to index field from another class

angularjs - 在 AngularJS 中持久化身份验证 token

python - 使用身份验证时不存在用户匹配查询

python - 如何在 Ubuntu Trusty 上安全地使用 pip(带 SSL)?